操作系统:Windows Server 2008 R2 SP1(x64)
数据库:SQL Server 2008 R2 SP1(x64)
PHP:5.4.x
先用手动安装,fastcgi模式,这个网上教程很多,很快就装完了。再安装Microsoft Drivers for PHP for SQL Server,但是用PDO连接SQL Server 2008数据库时,提示“could not find driver1”,意即mssql驱动没有加载成功。在网页上执行phpinfo显示所有参数查看,果然没有加载mssql驱动!
根据微软驱动自带的帮助文档仔细核对:
To load the Microsoft Drivers for PHP for SQL Server when PHP is started, first move a driver file into your extension directory. Then, follow these steps:
To enable the SQLSRV driver, modify php.ini by adding the following line to the extension section, or modifying the line that is already there (this example uses the version 3.0 thread safe driver for PHP 5.3):
extension=php_sqlsrv_53_ts.dll 로그인 후 복사 |
To enable the PDO_SQLSRV driver, modify php.ini by adding the following line to the extension section, or modifying the line that is already there (this example uses the version 3.0 thread safe driver for PHP 5.3):
extension=php_pdo_sqlsrv_53_ts.dll 로그인 후 복사 |
If you want to use the PDO_SQLSRV driver, the php_pdo.dll must be available, either as a built-in extension, or as a dynamically-loaded extension. If you need to load the PDO_SQLSRV driver dynamically, the php_pdo.dll must be present in the extension directory and the the following line needs to be in the php.ini:
extension=php_pdo.dll 로그인 후 복사 |
Restart the Web server.
发现PHP的安装目录下根本没有php_pdo.dll文件,所以加载失败也不足为奇。
捣鼓了几个小时,最后没有办法,卸载PHP,通过Web Flatform Installer来安装PHP,在弹出的可选组件中,赫然有“Microsoft SQL Server 2012 Native Client”一项,不太明白为什么,我自己的机器上已经有2008 R2版的Native Client了呢,会不会多此一举徒劳无功呢?然而安装结束后,连IIS都不用重启,就可以连上数据库了,震精,哥彻底无语!
看来最新的php已经修改了SQL Server驱动加载的模式,不再需要php_pdo.dll了,却需要一个最新的Native Client,可惜微软的文档上没有说明,让我抓瞎了好久。
另外,Web Flatform Installer是个不错的东西,推荐一下。