【发布时间】:2018-05-02 21:54:26
【问题描述】:
我正在尝试使用 PHP 连接到 MS SQL Server,但失败了。我正在运行 PHP7.2,并且我已经安装了 Microsoft Drivers 5.2 for PHP for SQL Server 和 Microsoft ODBC Driver 17 for SQL Server。
这是我正在使用的代码...
$serverName = "severname\MSSQLSERVER";
$conn_array = array (
"UID" => "username",
"PWD" => "password",
"Database" => "databasename",
);
$conn = sqlsrv_connect($serverName, $conn_array);
if ($conn){
echo "connected";
}else{
die(print_r(sqlsrv_errors(), true));
}
这是我收到的错误消息...
> Array (
> [0] => Array (
> [0] => 08001
> [SQLSTATE] => 08001
> [1] => 87
> [code] => 87
> [2] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87].
> [message] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87].
> ) [1] => Array (
> [0] => HYT00 [SQLSTATE] => HYT00
> [1] => 0 [code] => 0
> [2] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
> [message] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
> ) [2] => Array (
> [0] => 08001
> [SQLSTATE] => 08001
> [1] => 87 [code] => 87
> [2] => [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while
> establishing a connection to SQL Server. Server is not found or not
> accessible. Check if instance name is correct and if SQL Server is
> configured to allow remote connections. For more information see SQL
> Server Books Online. [message] => [Microsoft][ODBC Driver 17 for SQL
> Server]A network-related or instance-specific error has occurred while
> establishing a connection to SQL Server. Server is not found or not
> accessible. Check if instance name is correct and if SQL Server is
> configured to allow remote connections. For more information see SQL
> Server Books Online.
> )
> )
更新: 删除实例名称后出现此错误... SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]用户 'USERNAME 登录失败'。
【问题讨论】:
-
您的实例名称/又名架构名为
MSSQLSERVER?不清楚您可能混淆了什么或可能完全错误。 -
感谢您提供帮助。删除实例名称后,我收到此错误... SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]用户 'USERNAME' 登录失败。
-
请更新您遇到的新错误问题。
标签: php sql sql-server