使用WAMP连接PHP和SQL Server

时间:2013-03-07 15:42:29

标签: 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));
}

我已将.dll放在ext文件中,并且已经在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 ) )

任何帮助将不胜感激。谢谢。

2 个答案:

答案 0 :(得分:1)

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

这就是答案。我下载了Microsoft®SQLServer®2012Native Client,一切都像魅力一样。我搜索了这个链接的高低,现在我在这里分享它,希望能帮助那些像我一样寻找它的人。

答案 1 :(得分:0)

@plasmy,谢谢你。我也一直在搜索这个工作。页面顶部的下载链接为您提供了一个文本文件,其中包含有关如何下载文件的说明,这非常重要。本机客户端的直接链接在这里:

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