[英]Connecting PHP and SQL Server using WAMP
I am trying to connect my PHP with SQL Server. 我正在尝试将PHP与SQL Server连接。 I have to go to the field to test it, so I was configuring a laptop with the necessary settings.
我必须去现场进行测试,所以我正在使用必要的设置配置笔记本电脑。 In the desktop I currently work at, the connection works properly.
在我当前使用的桌面上,连接正常工作。 But in the laptop, it won't connect.
但是在笔记本电脑中,它无法连接。 Here is the code I am using:
这是我正在使用的代码:
$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));
}
I have placed the .dlls in the ext file and I have written the extension in the php.ini but somehow it still won't work. 我已将.dlls放在ext文件中,并将扩展名写在php.ini中,但以某种方式仍然无法正常工作。 This is the error I am getting:
这是我得到的错误:
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 ) )
Any help will be appreciated. 任何帮助将不胜感激。 Thank you.
谢谢。
http://www.microsoft.com/en-us/download/details.aspx?id=29065#SNAC http://www.microsoft.com/zh-cn/download/details.aspx?id=29065#SNAC
This is the answer. 这就是答案。 I downloaded the Microsoft® SQL Server® 2012 Native Client and everything worked like a charm.
我下载了Microsoft®SQLServer®2012 Native Client,一切正常。 I searched high and low for this link so now I share it here in hopes to help anyone who is looking for it like me.
我搜索了此链接的上下限,因此现在在这里分享它,希望能帮助像我一样寻找它的任何人。
@plasmy, thanks for this. @plasmy,谢谢你。 I also have searched all over to get this working.
我也搜索了所有以使此工作。 The download link on top of the page gives you a text file with instructions on how to download the file, which is seriously wtf.
页面顶部的下载链接为您提供了一个文本文件,其中包含有关如何下载该文件的说明,该文件非常重要。 The direct link for the native client is here:
本地客户端的直接链接在这里:
http://go.microsoft.com/fwlink/?LinkID=239648&clcid=0x409 http://go.microsoft.com/fwlink/?LinkID=239648&clcid=0x804
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.