首先,数据库连接。以下语句为示例语句,请根据实际情况修改
$conn = @new COM(“ADODB.Connection”) or die (“ADO Connection faild.”);
$connstr = “DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=” . realpath(“data.mdb”);
$conn->Open($connstr);
数据查询
$rs = @new COM(“ADODB.RecordSet”);
$rs->Open(“select from user”,$conn,1,3);
/ 循环读取数据 */
while(!$rs->eof){
echo $rs->Fields[“username”];
echo “<br/>”;
$rs->Movenext();
}
数据更新
$rs = @new COM(“ADODB.RecordSet”);
$username = “xefan.cn”;
$password = www.xefan.cn;
$rs->Open(“update user set username=’$username’,password=’$password’ where id=15”,$conn,1,3);
数据插入
$rs = @new COM(“ADODB.RecordSet”);
$username = “xefan.cn”;
$password = www.xefan.cn;
$rs->Open(“insert into user (username,password) values (‘$username’,’$password’)”,$conn,1,1);
数据删除
$rs = @new COM(“ADODB.RecordSet”);
$rs->Open(“delete from user where id=13”,$conn,1,1);
关闭连接
$conn->close();