I downloaded adodb a few days ago and wanted to use adodb to connect to the access database. Later, I was able to connect, but I couldn't update or insert records. I don't know why no one has answered my troubled question until now, so I gave up on adodb. , using PHP's own ODBC, but it is very inconvenient to use, so I wrote the following functions, which have not been encapsulated into classes. I hope it can help friends who have the same problem
<?php
/*
*@access class
* insert,update,delete record
* version 1.0
* date 2005.6
* power by Samsun Manzalo (34n Zhu Bajie)
* www.knowsky.com
*/
//====================================
// insert record
//Insert record
//====================================
function insRd($table,$field){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$tmpA = explode(',',$field);
$ins = '';
for($i=0;$i<count($tmpA);$i++){
$ins.= "'".$_POST[$tmpA[$i]]."',";
}
$ins = substr($ins,0,-1);
$sql = "INSERT INTO ".$table." (".$field.") VALUES (".$ins.")";
//echo $sql;exit;
$query = @odbc_do($connid,$sql);
}
//====================================
//get one record detail
// Get the detailed information of the current record
//====================================
function getInfo($table,$field,$id,$colnum){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "select * from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
if(odbc_fetch_row($query)){
for($i=0;$i<$colnum;$i++){
$info[$i] = odbc_result($query,$i+1);
}
}
return $info;
}
//====================================
//get record list
// Get the record list
//====================================
function getList($table,$field,$colnum,$condition,$sort="order by id desc"){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "select * from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
$rdList[$i] = getInfo($table,$field,odbc_result($query,1),$colnum);
$i++;
}
return $rdList;
}
//====================================
//get record list condition
// Get the record list
//====================================
function getFieldList($table,$field,$fieldnum,$condition="",$sort=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "select ".$field." from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
for($j=0;$j<$fieldnum;$j++){
$info[$j] = odbc_result($query,$j+1);
}
$rdList[$i] = $info;
$i++;
}
return $rdList;
}
//====================================
//update record
//Update record
//====================================
function updateInfo($table,$field,$id,$set){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "update ".$table." set ".$set." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//====================================
// record delete
// Delete record
//====================================
function delRd($table,$field,$id){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "delete from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//====================================
// record delete cat
// Delete record (condition)
//====================================
function delOrRd($table,$condition){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "delete from ".$table." where ".$condition;
$query = @odbc_do($connid,$sql);
}
//====================================
//count record
// Get the number of records
//====================================
function countRd($table,$condition=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("Database connection error!");
$sql = "select count(*) as num from ".$table." ".$condition;
$query = @odbc_do($connid,$sql);
odbc_fetch_row($query);
$num = odbc_result($query,1);
return $num;
}
?>