2011-08-30 49 views
0

編輯:對不起,我想清楚是什麼問題。我正在編輯錯誤的文件。連接到本地主機上的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. 
     ) 

) 
+0

請重新發布錯誤轉儲,因爲它在您的頁面上查看源代碼時出現,因此它的格式是可讀的。 –

+0

@ Michael - 對不起,我剛更新了編輯。 – isorfir

回答

0

愚蠢的錯誤,我正在編輯錯誤的文件。

0

如果PHP不使用相同的方法來連接作爲SQLCMD你會看到奇怪的結果。不只是使用TCPIP來連接(也就是說你的服務器應該設置爲在TCPIP上進行偵聽)。

+0

我不太確定你在說什麼。我相信我已經設立了聽TCPIP。 – isorfir

相關問題