我使用ff。代碼,但它有一個錯誤如何連接ms sql到php
<?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));
}
?>
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.))
似乎是登錄數據庫的問題,你能確保你提供正確的憑據嗎? – user1314742
我已經檢查過很多次了。細節是正確的 – Melo