Home > Backend Development > PHP Tutorial > PHP技巧--通过COM使用ADODB_PHP

PHP技巧--通过COM使用ADODB_PHP

WBOY
Release: 2016-06-01 12:30:53
Original
793 people have browsed it

要实现下列功能,请确保 php.ini 中的 com.allow_dcom 选项已设为 true。

一、准备工作

新建一个ACCESS数据库,并命名为db.mdb,然后在这个数据库中新建一个表 comtest,包含 id 和 title 两个字段,最后随便插入一些数据。

二、实现代码

// 就是刚建的数据库
$db = 'd:\\wwwroot\\db.mdb';

// 建立连接,并打开
$conn = new COM('ADODB.Connection') or die('can not start Active X Data Objects');
//$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");

// 执行查询并输出数据
$rs = $conn->Execute('SELECT * FROM comtest');
?>




while (!$rs->EOF) {
echo '';
echo '';
echo '';
echo '';
$rs->MoveNext();
}
?>
ID Title
'. $rs->Fields['id']->Value .''. $rs->Fields['title']->Value .'

// 释放资源
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template