我有一台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 Authentication访问数据库,因此我没有指定UID和PWD参数。
请帮助我连接到SQL server。
发布于 2016-09-30 01:55:07
发布于 2016-09-30 02:32:24
从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。
https://stackoverflow.com/questions/39775743
复制相似问题