請依照下面步驟來配置:或參考微軟官方網頁
1.先確認自己的系統是否為以下其中之一:
Windows Server 2003 Service Pack 1
Windows XP Service Pack 3
Windows Vista Service Pack 1 or later
Windows Server 2008
Windows Server 2008 R2
Windows 7
2.下載sqlsrv套件:下載SQLSRV20.EXE,若是WIN7則下載SQLSRV30.EXE
下載後解壓縮可以看到許多dll檔案,這時請打開您的phpinfo頁面,查看
Zend Extension Build,我的編制為:API220090626,TS,VC9,故請將壓縮後的dll檔,其後面有ts_vc9的檔案附至到php預設的ext資料夾裡,並且配置php.ini:
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll
3.下載Microsoft SQL Server 2008 R2 Native Client:XP用戶點選 Download the X86 package,更進階64為原則點選Download the X64 package
安裝完後重新啟動web server ,並且撰寫測試ms sql server 的程式碼:
$DB_HOST1 = "";//IP順利列出資料表則大功告成唷!!
$DB_LOGIN1 = "";//uid
$DB_PASSWORD1 = "";//pwd
$DB_NAME1 = "";//db name
$serverName = $DB_HOST1;
$connectionInfo = array("UID"=>$DB_LOGIN1, "PWD"=>$DB_PASSWORD1, "Database"=>$DB_NAME1, "CharacterSet" => "UTF-8" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$sqlstr = "select * from Account";
$res = sqlsrv_query($conn,$sqlstr,$params,$options);
$num = sqlsrv_num_rows($res);
for($i=0;$i<$num;$i++)
{
$r = sqlsrv_fetch_array($res);
echo $r[0].' '.$r[1].'
';
}
?>