Php + odbc + access database operation function, tested in windows through _ PHP Tutorial

Source: Internet
Author: User
Php + odbc + access database operation function, passed the test in windows. I downloaded adodb a few days ago and wanted to use it to connect to the access database. later, I connected the database. However, I cannot update or insert records. I don't know why no one has answered me that question.

I downloaded adodb a few days ago and wanted to use it to connect to the access database. later I connected it, but I cannot update or insert records, I don't know why no one has answered the worried question yet. I gave up adodb and used my odbc in php, but it was inconvenient to use. I wrote the following functions, it has not been encapsulated into a class, so I hope to help my friends who have the same problem

/*
* @ Access class
* Insert, update, delete record
* Version 1.0
* Date 2005.6
* Power by Samsun manzaro (34n pig)
* 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 $ 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
// Obtain 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
// Obtain 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 ."
";
$ I = 0;
While (odbc_fetch_row ($ query )){
$ RdList [$ I] = getInfo ($ table, $ field, odbc_result ($ query, 1), $ colnum );
$ I ++;
}
Return $ rdList;
}


// ==============================================
// Get record list condition
// Obtain 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 ."
";
$ 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); 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 a 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
// Obtain 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;
}

?>

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.