2013-03-07 104 views
0

我想將我的PHP與SQL Server連接起來。我必須去現場測試它,所以我正在配置一臺具有必要設置的筆記本電腦。在我目前工作的桌面中,連接正常工作。但在筆記本電腦中,它不會連接。這裏是我使用的代碼:使用WAMP連接PHP和SQL Server

$serverName = "server"; //serverName\instanceName 

$connectionInfo = array("Database"=>"DB", "UID"=>"user", "PWD"=>"pass"); 
$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)); 
} 

我已經放在EXT文件中的.DLL文件,我已經寫在php.ini的擴展,但不知何故它仍然是行不通的。這是我得到的錯誤:

Connection could not be established. 
Array ([0] => Array ([0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712) [1] => Array ([0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified)) 

任何幫助將不勝感激。謝謝。

+1

讀取錯誤,它看起來像你需要下載SQL Server客戶端上你的筆記本電腦:http://go.microsoft.com/fwlink/? LinkId = 163712 – Sam 2013-03-07 15:43:30

+0

事情是我已經擁有它 – plasmy 2013-03-07 15:47:52

+0

考慮使用[PDO](http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access- -net-12059)以獲得更大的靈活性。 – 2014-10-08 15:33:32

回答

1

http://www.microsoft.com/en-us/download/details.aspx?id=29065#SNAC

這就是答案。我下載了Microsoft®SQLServer®2012本機客戶端,一切都像魅力一樣。我搜索這個鏈接的高低,所以現在我在這裏分享它,希望幫助任何像我一樣尋找它的人。

+0

有許多產品可供下載,但沒有名稱爲Microsoft®SQLServer®2012 Native Client的產品。您下載了哪個產品來解決此問題? – 2013-08-06 07:43:58

+1

我發佈的鏈接是我下載並運行的。 – plasmy 2013-08-09 13:27:47

0

@plasmy,謝謝你。我也搜遍了所有的工作。頁面頂部的下載鏈接爲您提供了一個文本文件,其中包含有關如何下載該文件的說明,這是嚴重跆拳道。直接鏈接爲本地客戶端是在這裏:

http://go.microsoft.com/fwlink/?LinkID=239648&clcid=0x409