ADODB test code

Source: Internet
Author: User

Copyright statement: original works can be reproduced. During reprinting, you must mark the original publication, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://blog.csdn.net/mayongzhan-ma yongzhan, myz, mayongzhan
 
Create a temp folder in the local folder.
Adodbtest. php
 
<? Php <br/> require_once ('newadodb. php'); <br/>?> <Br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = GBK "/> <br/> <title> </title> <br/> </pead> <br/> <body> <br/> <? Php <br/>/* <br/> * @ author ma yongzhan <br/> */<br/> $ adodb_fetch_mode = adodb_fetch_assoc; </P> <p> $ query = "select * from library"; </P> <p> // $ result = $ db-> execute ($ query) or die ($ db-> errormsg (); <br/> $ result = $ db-> selectlimit ($ query, 10, 1) or die ($ db-> errormsg (); // 10 </P> <p> while (! $ Result-> EOF) <br/>{< br/> echo $ result-> fields ['title']. "-". $ result-> fields ['author']. "<br/>"; <br/> $ result-> movenext (); <br/>}< br/> echo "<br/> [". $ result-> recordcount (). "rows] <br/> </B>"; // number of rows <br/> echo "<br/> [". $ result-> fieldcount (). "Fields] <br/> </B>"; // number of fields <br/> $ db-> close (); <br/>?> <Br/> </body> <br/> </ptml> <br/>

 
Adodbtest2.php
 
<? Php <br/> require_once ('newadodb. php'); <br/>?> <Br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = GBK "/> <br/> <title> </title> <br/> </pead> <br/> <body> <br/> <? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> $ Title = $ db-> qstr ("myz "); <br/> $ author = "123"; <br/> $ query = "insert into library (title, author) values ($ title, $ author )"; </P> <p> $ result = $ db-> execute ($ query) or die ($ db-> errormsg ()); </P> <p> if ($ result) <br/>{< br/> echo "Last inserted ID is ". $ db-> insert_id (); <br/>}</P> <p> $ db-> close (); <br/>?> <Br/> </body> <br/> </ptml> <br/>

 
Adodbtest3.php
 
<? Php <br/> require_once ('newadodb. php'); <br/>?> <Br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = GBK "/> <br/> <title> </title> <br/> </pead> <br/> <body> <br/> <? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> $ Title = $ db-> qstr ("myz "); <br/> $ author = "123"; <br/> $ query = "delete from library where id = 4 "; </P> <p> $ result = $ db-> execute ($ query) or die ($ db-> errormsg ()); </P> <p> if ($ result) <br/>{< br/> echo $ db-> affected_rows (). "rows deleted"; <br/>}</P> <p> $ db-> close (); <br/>?> <Br/> </body> <br/> </ptml> <br/>

 
Adodbtest4.php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> require_once ("newadodb. PHP "); </P> <p> $ query = $ db-> prepare (" insert into library (title, author) values (?, ?) "); </P> <p> $ DATA = file (" list.txt "); </P> <p> foreach ($ data as $ L) <br/>{< br/> $ arr = explode (",", $ L); <br/> $ result = $ db-> execute ($ query, array ($ arr [0], $ arr [1]) or die ("error in query: $ query. ". $ db-> errormsg (); <br/>}</P> <p> $ db-> close (); <br/>?> <Br/>
 
Adodbtest5.php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> require_once ("newadodb. PHP "); </P> <p> $ db-> begintrans (); </P> <p> // first query <br/> $ query = "insert into library (title, author) values ('title A', 'author B ') "; <br/> $ result = $ db-> execute ($ query) or die (" error in query: $ query. ". $ db-> errormsg (); </P> <p> // use ID from first query in second query <br/> if ($ result) <br/>{< br/> $ id = $ db-> inse Rt_id (); <br/> $ query = "insert into library (title, author) values ($ id, 'usd 39.99 ')"; <br/> $ result = $ db-> execute ($ query) or die ("error in query: $ query. ". $ db-> errormsg (); <br/>}</P> <p> if ($ result) <br/>{</P> <p> $ db-> committrans (); <br/>}</P> <p> else <br/>{< br/> $ db-> rollbacktrans (); <br/>}</P> <p> $ db-> close (); <br/>?> <Br/>
 
Adodbtest6.php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> require_once ("newadodb. PHP "); </P> <p> $ query =" select * from library "; <br/> $ result = $ db-> cacheexecute (300, $ query) or die ($ db-> errormsg (); </P> <p> while (! $ Result-> EOF) <br/>{< br/> echo $ result-> fields [1]. "-". $ result-> fields [2]. ""; <br/> $ result-> movenext (); <br/>}< br/> $ db-> close (); </P> <p >?> <Br/>

 
Adodbtest7.php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> require_once ("newadodb. PHP "); </P> <p> $ query =" select title, ID from library "; <br/> $ result = $ db-> execute ($ query) or die ("error in query: $ query. ". $ db-> errormsg (); </P> <p> Print $ result-> getmenu ("library", '', false ); </P> <p> $ db-> close (); </P> <p >?> <Br/>

 
Adodbtest8.php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */<br/> require_once ("ADODB/toexport. inc. PHP "); <br/> require_once (" ADODB/tohtml. inc. PHP "); <br/> require_once (" newadodb. PHP "); <br/> $ query =" select title, ID from library "; <br/> $ result = $ db-> execute ($ query) or die ("error in query: $ query. ". $ db-> errormsg (); <br/> // echo rs2csv ($ result, false); <br/> // echo rs2tab ($ result, false ); <br/> echo rs2html ($ re Sult, false); <br/> $ db-> close (); <br/>?> <Br/>

 
Newadodb. php
 
<? Php <br/>/* <br/> * @ author ma yongzhan <br/> */</P> <p> require_once 'ADODB/ADODB. inc. PHP '; </P> <p> $ adodb_cache_dir = 'temp/'; </P> <p> $ mydbtype = 'mysql '; <br/> $ mydbhost = 'localhost'; <br/> $ mydbname = 'root'; <br/> $ mydbpass = 'myz '; <br/> $ mydb = 'adodbtest'; </P> <p> $ db = newadoconnection ($ mydbtype ); </P> <p> $ db-> connect ($ mydbhost, $ mydbname, $ mydbpass, $ mydb) or die ($ db-> errormsg ()); <br/>?> <Br/>

 
List.txt
ABC, BCD
SDF, dsfgg
Grwetg, dfsdf

 

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.