我用的是ff。代码,但它有错误
<?php
$serverName = "MELODY-PC\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"customerdb", "UID"=>"admin", "PWD"=>"reden");
$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));
}
?>
&#13;
Connection could not be established.
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 'admin'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'admin'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot open database "USE customerdb" requested by the login. The login failed. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot open database "USE customerdb" requested by the login. The login failed. ) [2] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'admin'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'admin'. ) [3] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot open database "USE customerdb" requested by the login. The login failed. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot open database "USE customerdb" requested by the login. The login failed. ) )
&#13;
答案 0 :(得分:0)
我个人使用:
if(mssql_connect('server_ip','user','password') === FALSE) die('Error Connecting to MySQL Server.');
但请注意,此功能已弃用。
答案 1 :(得分:0)
您的用户似乎已配置为使用Windows身份验证,但为了将sqlsrv_connect()
与凭据(UID和PWD)一起使用,用户必须具有SQL Server身份验证,而不是Windows身份验证。
This answer显示了如何创建SQL Server身份验证用户。