简体   繁体   English

PHP MSSQL(2012)提供错误:无法连接到SQL Server

[英]Php MSSQL(2012) giving error:Couldn’t connect to SQL Server

I am trying to fetch a set of fields from a Database on MSSQL Database on SQL Server 2012. This is a remote server and I am trying the following piece of code. 我正在尝试从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

It simply does not connect to the sql server. 它根本不连接到sql server。 It gives the error: Couldn't connect to SQL Server on IPAddress/SQLExpress 它给出错误:无法连接到IPAddress / SQLExpress上的SQL Server

I tried checking all configurations like TCP/IP through SQL Server Config management. 我尝试通过SQL Server Config管理检查所有配置,例如TCP / IP。

Can someone please help? 有人可以帮忙吗?

Ensure remote connections over named pipes are enabled and make sure you're using a backslash before the instance name: 确保已启用通过命名管道的远程连接,并确保在实例名称之前使用反斜杠:

$myServer = "IPAddress\SQLExpress ";

If you'd like to enable connection over the default port (1433) this answer will help. 如果您想启用默认端口(1433)上的连接,此答案将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM