tagged “SQL Server”

PHP 5.3.X 连接MS SQL Server

| | 评论 (0) | TrackBacks (1)

最近做的一个项目需要用PHP连接到MS SQL Server,在公司安装的PHP是5.2版的,Windows平台的PHP Zip安装包解压后的扩展目录(ext)里有自带连接到SQL Server的驱动文件-php_mssql.dll,只需先将PHP目录的ntwdblib.dll拷贝到系统盘下windows/system32,然后修改php.ini,取消;extension=php_mssql.dll 前面的;,重启Apache服务器就可以了。

但是家里用的是WAMP集成安装包,PHP版本是5.3.2,扩展目录里没有php_mssql.dll,而且连ntwdblib.dll也没有,从PHP 5.2分别拷贝这两个文件到扩展目录和系统目录,重启Apache,提示mssql模块和php编译版本不匹配(如下图):


php-mssql-mismatch.PNG


在网上搜索了一下PHP 5.3.X 连接SQL Server的办法,有人也遇到了这个问题 (PHP Unable to Connect to MSSQL),原来PHP 团队在PHP 5.3 中移除了SQL Server的驱动和库,而微软自己开发了针对PHP的SQL驱动(SQL Server Driver for PHP),但是1.0版的不支持 PHP 5.3,1.1版本才支持,但即使用这种办法,也不是官方推荐的原生的支持,如果要用直接支持的办法,可以用ODBC来连接。这位作者对PHP 5.3连接 SQL Server的问题颇有研究,发了一系列的文章来说明问题的来龙去脉(No SQL Server Library for PHP 5.3 Just YetInstalling PHP 5.3 on Microsoft IISFinally a working SQL Server Driver for PHP 5.3Installing FastCGI and PHP for IIS 6.0)。 Finally a working SQL Server Driver for PHP 5.3 这篇文章的留言中有人给出了 他自己编译的PHP 5.3.0 连接 MS SQL Server所需的 php_mssql.dll 文件,但是这个文件之能用于VC9 PHP(何为VC9 PHP,请看补充内容)。

SQL Server in PHP 5.3  这篇帖子的回复里,有人提到PHP 5.3.1里面有 php_mssql.dll,于是到PHP 官方网站,却只提供PHP 5.2和最新的PHP 5.3.2下载,最后还是在WAMP网站提供的 PHP Addon中找到了PHP 5.3.1,拷贝mssql扩展文件到WAMP 的PHP扩展目录,问题解决!

补充:关于VC9 和VC6 版本的PHP

If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP

If you are using PHP with IIS you should use the VC9 versions of PHP

VC6 Versions are compiled with the legacy Visual Studio 6 compiler

VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64) installed

Do NOT use VC9 version with apache.org binaries


相关链接:

SQL Server in PHP 5.3  

PHP: Installation of extensions on Windows - Manual


Ads

Tags

和我聊天

Powered by Movable Type 4.1