MSSQL错误:将数据库上下文更改为“dbname”

时间:2016-07-30 09:50:50

标签: php sql-server web-services

我正在尝试使用php-mssql建立与数据库名称'dbname'的连接。它显示连接已成功完成并且连接已打开但是当我尝试在该数据库中执行create table query时,我收到错误 MSSQL错误:将数据库上下文更改为“dbname”。

这是我的代码:

<?php
$myServer = "123.456.88.99";
$myUser = "user1";
$myPass = "password";
$myDB = "dbname"; 

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB"); 
echo "connection done ".$selected; 
$query = "CREATE TABLE prasad(customer_name varchar(10), contact_name varchar(10), Address varchar(50), city varchar(50), country varchar(50))";
if(mssql_query( $conn, $query))
{
echo "table creation successfull";
}
else{
    echo "table not created";
    die( 'MSSQL error: ' . mssql_get_last_message());
}

注意:    数据库服务器和托管服务器是不同的服务器,这就是我输入ip地址代替'$ myServer'的原因。

0 个答案:

没有答案