A few days ago downloaded ADODB, want to use ADODB even Access database, and later even connected, but can not update and insert records, do not know why no one to me to answer that distress question, and then gave up the ADODB, using PHP own ODBC, but the use is very inconvenient, I wrote down the following functions, which are not encapsulated into classes, hoping to help a friend with the same problem.
/*
* @ Access Class
* Insert,update,delete Record
* Version 1.0
* Date 2005.6
* Power by Samsun Manzalo (34n Pig)
* www.knowsky.com
*/
//====================================
//Insert record
//Inserting Records
//=================================== =
Function Insrd ($table, $field) {
$connstr = "Driver=microsoft Access DRIVER (*.mdb);D Bq=database/email.mdb";
$connid = @odbc_connect ($connstr, "", "", Sql_cur_use_odbc) or Die ("Database connection Error!");
$tmpA = Explode (,, $field);
$ins =;
for ($i =0; $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 record details
//=================== =================
Function GetInfo ($table, $field, $id, $colnum) {
$connstr = "Driver=microsoft Access DRIVER (*. MDB);D Bq=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 Records listing
//============================ ========
Function GetList ($table, $field, $colnum, $condition, $sort = "ORDER BY id Desc") {
$connstr = "driver= Microsoft Access Driver (*.mdb);D Bq=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. "
";
$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 Records listing
//=================== =================
Function Getfieldlist ($table, $field, $fieldnum, $condition = "", $sort = "") {
$connstr = "DRIVER =microsoft Access Driver (*.mdb);D Bq=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. "
";
$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);D Bq=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
Deleting records
//====================================
function Delrd ($table, $field, $id) {
$connstr = "Driver=microsoft Access DRIVER (*.mdb);D Bq=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);D Bq=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
Number of records obtained
//====================================
function Countrd ($table, $condition = "") {
$connstr = "Driver=microsoft Access DRIVER (*.mdb);D Bq=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;
}
?>
http://www.bkjia.com/PHPjc/508382.html www.bkjia.com true http://www.bkjia.com/PHPjc/508382.html techarticle a few days ago downloaded ADODB, want to use ADODB even Access database, and later even connected, but can not update and insert records, also do not know why no one to me now to answer that distressed ...