Php access database class sharing

Source: Internet
Author: User
Php access database class sharing
This article introduces a class for php to operate access databases. For more information, see.

The code is as follows:

     Getlist ("select top 5 * FROM 'result' WHERE 'resultno' <12 order by 'resultno' DESC ")); echo $ access-> num_rows ("update 'conner' set 'connerip' = '2017. 35.142.101 'where' connerno' <83 "); */class Access {var $ databasepath, $ constr, $ dbusername, $ dbpassword, $ link; function Access ($ databasepath, $ dbusername, $ dbpassword) {$ this-> databasepath = $ databasepath; $ this-> username = $ dbusername; $ this-> password = $ dbpas Sword; $ this-> connect ();} function connect () {$ this-> constr = 'driver = {Microsoft Access DRIVER (*. mdb)}; DBQ = '. realpath ($ this-> databasepath ). '; $ this-> link = odbc_connect ($ this-> constr, $ this-> username, $ this-> password, SQL _CUR_USE_ODBC); if (! $ This-> link) echo "database connection failed! "; Return $ this-> link;} function query ($ SQL) {// Run SQL directly, which can be used to update or delete data. return @ odbc_exec ($ this-> link, $ SQL);} function fetch_array ($ query) {// get the record at the current pointer return odbc_fetch_array ($ query);} function fetch_row ($ query) {// basically the same as fetch_array (), but only the digital index return odbc_fetch_row ($ query);} function num_rows ($ SQL) {// return the number of rows affected by the SQL query return odbc_num_rows ($ this-> query ($ SQL);} function close () {// closes the database connection function odbc_close ($ this-> link );} Function getlist ($ SQL) {// Obtain the record list $ query = $ this-> query ($ SQL); $ recordlist = array (); while ($ row = $ this-> fetch_array ($ query) {$ recordlist [] = $ row;} return $ recordlist ;}}?>

ODBC is used in the preceding classes, instead of the ODBC data source. Directly Create A *. mdb file.

Appendix: Access code for some common COM operations:

     Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");?>

JS call Page js. php

     Execute ("select top 3 * FROM userstar where chk = 1 order by id DESC"); $ idgb = 1; while (! $ Rs-> EOF) {$ gbinf [$ idgb] ['id'] = $ rs-> Fields ['id']-> Value; $ gbinf [$ idgb] ['usname'] = $ rs-> Fields ['usname']-> Value; $ gbinf [$ idgb] ['usage'] = $ rs-> Fields ['usage']-> Value; $ gbinf [$ idgb] ['uspecoss'] = $ rs-> Fields ['uspecoss']-> Value; $ gbinf [$ idgb] ['usfile'] = $ rs-> Fields ['usfile']-> Value; $ gbinf [$ idgb] ['thumb'] = $ rs-> Fields ['thumb']-> Value; $ gbinf [$ idgb] ['usmessage'] = $ rs-> Fields ['usmessage']-> Value; $ rs-> MoveNext (); $ idgb ++ ;} $ rs-> Close (); $ rs = null; $ uhtml = ''; $ uhtml. ='
     
     
         '; For ($ I = 1; $ I <4; $ I ++) {$ uhtml. =' 
        ';} $ Uhtml. =' 
       
'; If ($ gbinf [$ I] ['usfile']) {$ uhtml. ='
'. $ Gbinf [$ I] ['Vince rovince ']. ''. $ gbinf [$ I] ['usname']; if ($ gbinf [$ I] ['usage']! = 0) {$ uhtml. = '('. $ gbinf [$ I] ['usage']. 'years old)
';} $ Uhtml. ='

'. $ Gbinf [$ I] ['usmessage'].'

';} $ Uhtml. ='
'; Echo "document. write ('". $ uhtml. "')";?>

Another example is to use this file path to determine the database path:

     Open ("DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ = $ db "); // print_r ($ _ POST ); if ($ _ POST ['name'] & $ _ POST ['tel'] & $ _ POST ['addr '] & $ _ POST ['email'] & $ _ POST ['goal'] & $ _ POST ['high'] & $ _ POST ['weight'] & $ _ POST ['message']) {$ addsql = "insert into d90usr ('name', 'tel', 'addr ', 'Email', 'goal', 'high', 'weight ', 'message') VALUES ('". $ _ POST ['name']. "','". $ _ POST ['tel']. "','". $ _ POST ['add']. "','". $ _ POST ['email ']. "','". $ _ POST ['goal']. "','". $ _ POST ['high']. "','". $ _ POST ['weight']. "','". strip_tags ($ _ POST ['message']). "')"; // echo'
     '. $ Addsql; $ rsadd = $ conn-> Execute ($ addsql); echo ''; echo'

Congratulations, your registration is successful. please wait for the staff to contact you!

'; Echo'

Back to activity homepage back to mall homepage

';}?>

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.