I downloaded ADODB a few days ago, want to use ADODB Access database, and then even connected, but can not update and insert records, also do not know why no one to me to answer the vexed question, and then gave up the ADODB, using PHP own ODBC, but the use is very inconvenient, Write down the following functions, not encapsulated into a class, hoping to be able to help friends with the same problem
<?php
/*
* @ Access Class
* Insert,update,delete Record
* Version 1.0
* Date 2005.6
* Power by Samsun Manzalo (34n Pig)
*/
//=====================================================
//Insert record
//Insert 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 <count ($tmpA); $i + +) {
$ins. = "". $_post[$tmpA [$i]]. "', ';
&NBSP
$ins = substr ($ins, 0,-1);
$sql = "INSERT into". $table. " (". $field.") VALUES (". $ins.");
//echo $sql; exit;
$query = @odbc_do ($connid, $sql);
}
//=======================================================================
//Get one record detail
// Gets the detail
//=======================================================================
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 a record list
//Getting Records lists
/ /=================================================================
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); The
//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
//Take a list of records
//=============================================================
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); The
//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 records
//= =====================================================================
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
//delete 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;
}
?>