在Windows上的PHP连接到MS SQL服务器 [英] Connect PHP on Windows to MS SQL Server

查看:87
本文介绍了在Windows上的PHP连接到MS SQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows上的Apache连接/ PHP到SQL Server上相同的Windows对话框。

我能够从我的Linux虚拟机连接到数据库,我可以从Windows命令行SQLCMD连接到SQL Server。我刚才似乎无法让PHP连接,所以我想我使用的是不正确的模块某处。我已经做了很多的阅读和似乎没有任何使这项工作。

任何想法?

2.2的Apache,PHP 5.2

  $ myServer上=\\ SQLEX $ P $干燥综合征
$ MYUSER =SA;
$将mypass =test1234;
$ MYDB =鳗鱼;mssql_connect($ myServer上,$ MYUSER,$为mypass)警告:mssql_connect()[function.mssql连接]:无法连接到服务器:\\ SQLEX $ P $干燥综合征中


解决方案

严重。不要使用MSSQL的驱动程序。使用Microsoft推出的SQLSRV驱动程序。我用了两个很长一段时间,而php_mssql司机真的应该去precated。

请确保您使用最新的PHP的SQLSRV驱动程序的版本。你可以找到最新的稳定版本(V2.0.1)在这里: HTTP: //www.microsoft.com/download/en/details.aspx?id=20098

这是说,里面还有V3公测的pre释放。

请确保你选择正确的驱动程序为您的PHP版本。最有可能的,你如果你使用快速CGI所需要的VC 9,你需要非线程安全的版本。砸在你PHP扩展目录,然后将其添加到您的php.ini文件。

然后,您安装SQL本机客户端的关键所在。如果你没有这种安装做,司机在水中死亡。你可以找到它头(向下​​搜索的页面实际封装): HTTP :?//www.microsoft.com/download/en/details.aspx ID = 3522

一旦你完成了这一切,你应该是金色的。请务必阅读附带的帮助文件的正确用法。

I'm trying to connect Apache/PHP on Windows to SQL Server on the same Windows box.

I am able to connect to the database from my linux virtual machine and I can connect to SQL Server with sqlcmd from the Windows command line. I just can't seem to get PHP to connect, so I assume I'm using an incorrect module somewhere. I've done lots of reading and nothing seems to make this work.

Any ideas?

Apache 2.2, PHP 5.2

$myServer = ".\SQLEXPRESS";
$myUser = "sa";
$myPass = "test1234";
$myDB = "eel";

mssql_connect($myServer, $myUser, $myPass)

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: .\SQLEXPRESS in

解决方案

Seriously. Don't use the MSSQL driver. Use the SQLSRV driver put out by Microsoft. I've used both for long periods of time, and the php_mssql driver really should be deprecated.

Make sure you use the most recent version of the SQLSRV driver for PHP. You can find the most recent stable release (v2.0.1) here: http://www.microsoft.com/download/en/details.aspx?id=20098

That said, there is also a pre-release of the v3 beta.

Make sure you pick the right driver for your version of PHP. Most likely, you need the vc 9. If your using fast-cgi, you'll need the non-thread safe version. Drop it in you php extensions directory and then add it to your php.ini file.

Then, it's essential that you install the SQL Native Client. If you don't have that installed, the driver is dead in the water. You can find it head (search down the page for the actual package): http://www.microsoft.com/download/en/details.aspx?id=3522

Once you've done all that, you should be golden. Make sure you read the included help file for the proper usage.

这篇关于在Windows上的PHP连接到MS SQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆