我想将我的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