我想將我的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))
任何幫助將不勝感激。謝謝。
讀取錯誤,它看起來像你需要下載SQL Server客戶端上你的筆記本電腦:http://go.microsoft.com/fwlink/? LinkId = 163712 – Sam 2013-03-07 15:43:30
事情是我已經擁有它 – plasmy 2013-03-07 15:47:52
考慮使用[PDO](http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access- -net-12059)以獲得更大的靈活性。 – 2014-10-08 15:33:32