<?php
/*******************************************
只支持没有用户名和密码的数据库
*******************************************/
class ms_access_class {
var $rs,$conn;
function ms_access_class($db_name){
$this->rs ="";
$this->conn = new COM('ADODB.Connection') or die('服务器ado对象未安装');
$this->conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$db_name;Persist Security Info=False");
}
function query($query_str){
$this->rs = $this->conn->Execute($query_str);
}
function next(){
if($this->rs!=""){
$this->rs->MoveNext();
}
}
function eof(){
if($this->rs<>""){
return $this->rs->EOF;
}
}
function field_value($field_name){
if($this->rs<>""){
return $this->rs->Fields[$field_name]->Value;
}
}
function destroy(){
if($this->rs<>""){
$this->rs->Close();
}
$this->conn->Close();
$this->rs = null;
$this->conn = null;
}
}
?>
//=====================================
使用代码
//====================
<?
$obj = new ms_access_class("你数据库的名称");
$obj->query("查询语句");
while(!$obj->eof()){
$obj->field_value(”字段名字”);
$obj->next();
}
$obj->destroy();//手工释放
?>