我使用 SQL Server 2016。我尝试通过 PHP 脚本(PHP 版本 8)连接它。我已经安装了驱动程序并在 php.ini 中添加了路径(与我的 PHP 版本相同):
...
extension=pdo_sqlsrv_80_nts
extension=pdo_sqlsrv_80_ts
extension=sqlsrv_80_nts
extension=sqlsrv_80_ts
...
这是我的脚本:
$serverName = "<ServerName>";
$connectionInfo = array( "Database"=>"<database>", "UID"=>"<user>", "PWD"=>"<pwd>");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
我遇到了以下错误:
Array
(
[0] => Array
(
[0] => IM006
[SQLSTATE] => IM006
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
[message] => [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
)
[1] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5701
[code] => 5701
[2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed database context to '<database>'.
[message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed database context to '<database>'.
)
[2] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5703
[code] => 5703
[2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed language setting to us_english.
[message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed language setting to us_english.
)
)
有什么想法可能出了问题吗? 谢谢你的帮助