If you have not used Adodb, read this article: Introduction to ADODB and connection to simple mysql instance 1. execute () is used for direct query. check the following php code. I have commented it out in detail! & Amp; lt ;? Php //
If you have not used Adodb, read this article: Introduction to ADODB and connection to simple mysql instances.
1. Execute () is used for direct query. check the following php code. I have noted it in detail!
Connect ('localhost', 'root', '', 'Volunteer'); // sets the character encoding $ conn-> Execute (" set names utf8 "); /* the global variable $ ADODB_FETCH_MODE is used to set the field index or associated index. The value can be: * Digital Index: ADODB_FETCH_NUM, associated index: ADODB_FETCH_ASSOC */$ ADODB_FETCH_MODE = adodb_fetch_as; $ res = $ conn-> Execute ("select * from vol_msg"); if (! $ Res) {print $ conn-> ErrorMsg ();} else {while (! $ Res-> EOF) {/* the record set returns the top record from the execution method. it can be moveFirst (), moveLast (), moveNext (), move ($ n) METHOD * indicates a specified record in the access record set, as shown in */print $ res-> fields ['mid ']. "--". $ res-> fields ['name']."
"; $ Res-> MoveNext () ;}$ res-> close (); $ conn-> close ();?>
Running result:
1 -- the php point-to-point URL is www.phpddt.com
2 -- php Tutorial Learning Network
Note: FetchNextObject () returns each record as an object. the above results can also be implemented. the implementation code is as follows:
while ($row = $res->FetchNextObject()) {print $row->mid."--".$row->name."
";}
2. buffer query:
ADODB provides a buffer mechanism. CacheExecute () stores the query results in a buffer file. when the same query statement is used again in the future, data is directly read from the buffer file, it greatly provides website performance. $ ADODB_CACHE_DIR: specify the Cache directory and use the absolute path. See the following php code:
$ ADODB_CACHE_DIR = "/var/tmp/adodb_cache"; // absolute buffer file address $ SQL = "select id, name from student_msg "$ res = & $ db-> CacheExecute (800, $ SQL); // timeout (seconds), the buffer will be updated after S // CacheFlush () used to clear the buffer