1、数据写入方法:
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" . realpath("hydb/#db#.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ); //连接数据源
$sql="insert into openid (nam,gsid) values('$fromUsername',’$gsid’)";
$result=odbc_exec($connid,$sql); //执行语句
if($result) echo "successful";
else echo "failed";
odbc_close($connid); //关闭 ODBC 连接
2、数据读取方法:
$conn=new COM("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" . realpath("hydb/#db#.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ); //连接数据源
$sql ="select * from config";
$query = odbc_exec($connid, $sql);
if($query){
while (odbc_fetch_row($query)){
echo odbc_result($query,"wxid")."</br>"; //循环输出字段为wxid的数据
echo odbc_result($query,"gsid")."</br>";
}
}else{
print "No data";
}
odbc_close($connid);
3、删除数据方法:
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
$conn->Open($connstr);
$query = "delete from userinfo where uid=1";
$result =$conn->Execute($query);
if($result)
echo "删除成功";
else
echo "删除失败";
4、更新数据方法:
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
$conn->Open($connstr);
$query = "update userinfo set username='ganjun' where uid=2";
$result =$conn->Execute($query);
if($result)
echo "更新数据成功";
else
echo "更新数据失败";