2

我正在尝试从 SQL Server 2012 上的 MSSQL 数据库上的数据库中获取一组字段。这是一个远程服务器,我正在尝试以下代码。

//MSSQL Server for retrieving the Member name from Member ID:

//mssql.secure_connection = On
// Need to upload ntwdblib.dll from net

$myServer = "IPAddress/SQLExpress "; // host/instance_name
$myUser = "ID"; // username
$myPass = "pass"; // paasword
$myDB = "dbname"; // database name

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

// select a database to work with
$selected = mssql_select_db("sportsclub", $dbhandle)
or die("Couldn’t open database $myDB");

echo "You are connected to the " . $myDB . " database on the " . $myServer . ".";

$query = "SELECT first_name, last_name";
$query .= "FROM members ";
$query .= "WHERE member_id='".$row['member_id']."'"; 
 // your database query
$result = mssql_query($query);
while($row = mssql_fetch_assoc($result))
{
echo "<td>" . $rows["first_name"] . $rows["last_name"] . "</td>";
}
// close the connection
mssql_close($dbhandle);




//Ended MSSQL Connection

它根本不连接到sql server。它给出了错误:无法连接到 IPAddress/SQLExpress 上的 SQL Server

我尝试通过 SQL Server 配置管理检查 TCP/IP 等所有配置。

有人可以帮忙吗?

4

1 回答 1

0

确保启用了通过命名管道的远程连接,并确保您在实例名称前使用了反斜杠:

$myServer = "IPAddress\SQLExpress ";

如果您想通过默认端口(1433)启用连接,这个答案会有所帮助。

于 2013-08-15T19:59:07.723 回答