php下连接mssql2005的代码_PHP教程
程序员文章站
2022-05-11 19:06:24
...
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.测试代码
$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");
?>
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.测试代码
复制代码 代码如下:
$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");
?>
上一篇: php入门(1)
推荐阅读
-
CentOS7.0下安装PHP5.6.30服务的教程详解
-
windwos下使用php连接oracle数据库的过程分享
-
IIS下配置Php+Mysql+zend的图文教程(完整版)
-
PHP下使用mysqli的函数连接mysql出现warning: mysqli::real_connect(): (hy000/1040): ...
-
Windows环境下安装PHP Pear的方法图文教程
-
PHP面向对象的使用教程 简单数据库连接
-
php下获取http状态的实现代码
-
测试php连接mysql是否成功的代码分享
-
windows7下安装php的imagick和imagemagick扩展教程
-
浅谈Windows下 PHP4.0与oracle 8的连接设置