php下连接mssql2005的代码
程序员文章站
2023-04-07 13:26:14
1.下载以下两个文件,放入php ext目录及system32 php_sqlsrv_52_ts_vc6.dll (线程安全) php_sqlsrv_52_nts_vc6....
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");
?>
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");
?>