Phpodbcaccess database control function

Source: Internet
Author: User
I downloaded adodb a few days ago and wanted to use it to connect to the access database. later I connected the database, but I cannot update or insert records, I don't know why no one has answered the worried title yet. I gave up adodb and applied my odbc in php,

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

/*
* @ Access class
* Insert, update, delete record
* Version 1.0
* Date 2005.6
* Power by Samsun manzaro (34n pig)
*/

// ================================================ ====================
// Insert record
// Insert records
// ================================================ ====================
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'. $ table. '('. $ field. ') VALUES ('. $ ins .')';
// Echo $ SQL; exit;
$ Query = @ odbc_do ($ connid, $ SQL );
}


// ================================================ ======================================
// Get one record detail
// Obtain the specific 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

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.