php下连接mssql2005的代码

前端之家收集整理的这篇文章主要介绍了php下连接mssql2005的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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.测试代码
<div class="codetitle"><a style="CURSOR: pointer" data="4215" class="copybut" id="copybut4215" onclick="doCopy('code4215')"> 代码如下:

<div class="codebody" id="code4215">
<?PHP
$serverName = "127.0.0.1";
$connectionInfo = array("Database"=>"TestDB","UID"=>"test","PWD"=>"test");
$conn = sqlsrv_connect($serverName,$connectionInfo);
if($conn) {
echo "Connection established.
";
} else {
echo "Connection could not be established.
";
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']."
";
}
sqlsrv_close($conn);
echo "
Done
";
echo date("Y-m-d h:i:s");
?>

原文链接:https://www.f2er.com/php/28181.html

猜你在找的PHP相关文章