我有一个Windows Azure服务器,我想从PHP应用程序连接到MSSQL服务器。但是,当我尝试连接到数据库时,会弹出一条错误消息,说明......
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) )
我使用此代码连接数据库..
<?php
$serverName = "AZR-SRV-MAP01"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"EmpSys");
$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));
}
?>
我使用Windows身份验证访问数据库,因此我没有指定UID
和PWD
参数。
请帮我连接到SQL服务器。
答案 0 :(得分:0)
您可以查看此已发布的有关此主题的答案。这似乎可以帮助你。
祝你好运:)答案 1 :(得分:0)
从PHP连接到MSSQL数据库的工作代码(感谢gofr1)..
<?php
$serverName = "server_name"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"db_name");
$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));
}
?>
修改强>
您需要打开Windows身份验证,并在IIS设置中设置匿名身份验证。通过本地/域帐户授权SQL Server。