Home  >  Article  >  php教程  >  PHP通过COM使用ADODB的简单例子

PHP通过COM使用ADODB的简单例子

WBOY
WBOYOriginal
2016-06-13 12:34:54980browse

要实现下列功能,请确保 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;
?>
Statement:
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