2013-03-07 133 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