64位IIS7下的PHP 5.4配置及如何連接SQL Server 2008


操作系統: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:

  1. 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
  2. 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
  3. 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是個不錯的東西,推薦一下。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM