編輯:對不起,我想清楚是什麼問題。我正在編輯錯誤的文件。連接到本地主機上的SQL Server的PHP返回錯誤定位服務器/實例指定
我(嘗試)使用PHP 5.3.5連接到我的SQL SERVER 2005,但它一直都是麻煩。在本地機器上,如果我使用SQLCMD -S (local) -U sqlUser -P 1234 -d MyTable
,它連接正常。但是下面的代碼會產生一個錯誤:
<?php
$myServer = "(local)";
$myUser = "sqlUser";
$myPass = "1234";
$myDB = "MyTable";
$connectionInfo = array("Database"=> $myDB, "UID" => $myUser, "PWD" => $myPass);
//connection to the database
try{
$dbhandle = sqlsrv_connect($myServer, $connectionInfo)
or die(print_r(sqlsrv_errors(), true));
}catch(Exception $e){
echo "<pre>";
print_r($e);
echo "</pre>";
die;
}
?>
我該如何讓PHP連接到我的SQL Server?
完全錯誤:
Array
(
[0] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
[message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
)
[1] => Array
(
[0] => HYT00
[SQLSTATE] => HYT00
[1] => 0
[code] => 0
[2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
[message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
)
[2] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 10.0]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][SQL Server Native Client 10.0]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.
)
)
請重新發布錯誤轉儲,因爲它在您的頁面上查看源代碼時出現,因此它的格式是可讀的。 –
@ Michael - 對不起,我剛更新了編輯。 – isorfir