php下串連mssql2005的代碼
來源:互聯網
上載者:User
1.下載以下兩個檔案,放入php ext目錄及system32
php_sqlsrv_52_ts_vc6.dll (安全執行緒)
php_sqlsrv_52_nts_vc6.dll (非安全執行緒)
vc6用於Apache,vc9用於IIS
2.修改php.ini
extension=php_sqlsrv_52_ts_vc6.dll
3.下載sqlncli.msi,微軟官方可以下
安裝的時候提示是sql server 2008的,不過2005也是可以用的。
4.測試代碼
複製代碼 代碼如下:
<?php
$serverName = "127.0.0.1";
$connectionInfo = array("Database"=>"TestDB","UID"=>"test","PWD"=>"test");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn) {
echo "Connection established.<br>";
} else {
echo "Connection could not be established.<br>";
die(print_r(sqlsrv_errors(), true));
exit();
}
$sql = "select * from T_Employee";
$result = sqlsrv_query($conn,$sql);
$data = array();
while($row=sqlsrv_fetch_array($result)) {
$data[] = $row;
}
foreach($data as $p) {
echo $p['Name']."<br>";
}
sqlsrv_close($conn);
echo "<br> Done <br>";
echo date("Y-m-d h:i:s");
?>