Summary of ADODB query statements

Source: Internet
Author: User
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

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.