我正在进行简单的连接测试,以检查我是否可以使用PHP代码中的Windows身份验证连接到远程主机上运行的MSSQLServer。我正在使用Apache2.4.16和PHP5.5.28运行XAMP2。
我的代码如下:
<?php
$serverName = "serverName\instanceName"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"dbName");
$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));
}
?>
我收到以下错误:
Connection could not be established.
Array ( [0] => Array (
[0] => 08001 [SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. )
[1] => Array (
[0] => HYT00 [SQLSTATE] => HYT00
[1] => 0 [code] => 0
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired )
[2] => Array (
[0] => 08001 [SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][ODBC Driver 11 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 11 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. ) )
在Google上搜索我发现这可能是https://blogs.msdn.microsoft.com/brian_swan/2010/02/10/sql-server-driver-for-php-understanding-windows-authentication/
的问题但是进一步挖掘我发现只有IIS支持模拟,而apache上的mod_fastcgi不支持。有没有人遇到过simliar问题并且知道如何绕过它?
提前谢谢你。 佐勒菲卡尔