標籤:io os ar for strong sp 檔案 div on
今天遇到php串連mssql問題,按照網上各種嘗試,最後成功,再此記錄下。由於 php 5.3以後就不支援mssql。要下載相應的The SQL Server Driver for PHP。現在微軟官網有兩個安裝包:SQLSRV20.exe 和 SQLSRV30.exe
說下這兩個安裝包,20中有:
Driver file
PHP version
Thread safe?
Use with PHP .dll
php_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_vc6.dll
5.3
no
php5.dll
php_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_nts_vc9.dll
5.3
no
php5.dll
php_sqlsrv_53_ts_vc6.dll
php_pdo_sqlsrv_53_ts_vc6.dll
5.3
yes
php5ts.dll
php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll
5.3
yes
php5ts.dll
php_sqlsrv_52_nts_vc6.dll
php_pdo_sqlsrv_52_nts_vc6.dll
5.2
no
php5.dll
php_sqlsrv_52_ts_vc6.dll
php_pdo_sqlsrv_52_ts_vc6.dll
5.2
yes
php5ts.dll
30中有:
Driver file
PHP version
Thread safe?
Use with PHP .dll
php_sqlsrv_53_nts.dll
php_pdo_sqlsrv_53_nts.dll
5.3
no
php5.dll
php_sqlsrv_53_ts.dll
php_pdo_sqlsrv_53_ts.dll
5.3
yes
php5ts.dll
php_sqlsrv_54_nts.dll
php_pdo_sqlsrv_54_nts.dll
5.4
no
php5.dll
php_sqlsrv_54_ts.dll
php_pdo_sqlsrv_54_ts.dll
5.4
yes
php5ts.dll
其中52對應的php5.2的,vc9對應你的php 包的格式,例如(php-5.3.27-Win32-VC9-x86.zip) 。ts和nts的區別大家應該都知道的,也是要和你的php版本要對應的。
還有一點要注意就是下面這個說明,如果你下載的對應的php的diver是30.exe 的那你同時要安裝Microsoft SQL Server 2012 Native Client。
Version 3.0 of the driver requires Microsoft SQL Server 2012 Native Client. You can download Microsoft SQL Server 2012 Native Client from theSQL Server 2012 feature pack page.
Version 2.0 of the driver requires Microsoft SQL Server 2008 R2 Native Client. Click on the appropriate link below:
Download the X86 package
Download the X64 package
解壓sql Driver 包後要放到PHP的目錄下,同時增加
extension=php_pdo_mssql.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_sqlsrv_53_ts_vc9.dll
extension=ntwdblib.dll
這了還有一個重要的dll檔案就是ntwdblib.dll檔案,大家可以相應的去下載對應的sql版本的,每個版本不一樣,csdn上有下載的
sql 2005 對應編號 2000.80.194.0,sql 2008 對應編號 2000.80.2039.0。
下載ntwdblib.dll放到php的目錄下或者直接放在system32下。
重啟啟動apache伺服器,php.info中顯示如下介面:
說明sql配置已經成功。
一下是測試方法:
$serverName="(localhost)";
$connectionInfo=array("Database"=>"dbName","UID"=>"user","PWD"=>"pwd");
$conn=sqlsrv_connect($serverName,$connectionInfo);
if($conn){
echo"串連成功.<br/>";
}else{
echo"串連失敗.<br/>";
die(print_r(sqlsrv_errors(),true));
}
php 5.3.27 訪問 Sql2008 和 sql 2005