Ten instances of AdoDB [reproduced]

xiaoxiao2021-03-06  16

Ten instances of AdoDB [reproduced]

Ten instances of AdoDB

Transfer from http://www.ilovezhuzhu.net/discuz !/viewthread.php?tid=629&sid=2fe8hqj3 I want to learn PEAR, but the few posts seen on the Internet are quite high, so I have changed this. AdoDB's advantages have these few (online, not what I said): 1, speed is doubled fast than PEAR; 2, supported database types are much more than PEAR, can even support Access; 3, no need to install, no server Support (for novices, this is very important) I don't know what adoDB is or want to download Adodb's friends can go to this link: http://www.phpe.net/class/106.shtml addition, if Which brother translated the full text of Readme or know where there is a translation, please return to a post, thank you.

Tutorial Example 1: SELECT Statement Task: Connect a ACCESS database called Northwind to display the first two fields of each record. In this instance, we create an AdoCONNECTION object and use it to connect to a database. This connection uses a PConnect method, which is a persistent connection. When we want to query the database, we can call this connection with the execute () function. It returns an AdorecordSet object which is actually a cursor that Holds The Current Row in The Array FIELDS [] We use MoveNext () to turn from a record to the next record. NB: There is a very useful function SelectLimit is not used in this example, it can control the number of recorded records (such as only the top ten records, can Used as paging display). PHP code: ----------------------------------------------------------- --------------------------------------- PConnect ('northwind'); # Connect to a MS-Access database data source called Northwind $ RecordSet = & $ Conn-> EXECUTE ('SELECT * from products'): # From the Products data table, all data IF (! $ recordset) Print $ conn-> errormsg (); // If the data search occurs error display error message Else While ! $ recordset-> EOF) {Print $ RecordSet-> Fields [0]. ''. $ recordset-> fields [1]. '
'; $ recordset-> MoveNext (); // point to the next record } // list display data $ recordset-> close (); // Optional $ conn-> close (); // Optional?> -------------------------------------------------------------------------------------------------------------------- ---------------- -------------------------------------------- $ Recordset in $ Returning the current array in the recordset-> fields, digital indexing of the field (starting from 0). We move to the next record with the MoveNext () function. When the database searches the end, EOF Property is set to true. If Execute () occurs Error, Recordset returns a FLASE. $ RecordSet-> Fields [] array is generated in PHP database extensions. Some database extensions can only be indexed by digital index but cannot be used in the field name. If you insist on using the field name index, you should use the setFetchMode function. No matter which format index, the Recordset can be created by Execute () or selectLimit ().

PHP code: ----------------------------------------------- -------------------------------- $ db-> setfetchmode (adoDb_fetch_num); $ r1 = $ db-> execute ('select * from table'); // uses digital index $ db-> setfetchmode; $ r2 = $ db-> execute ('select * from table'); // uses field name index Print_R ($ RS1) -> Fields; # shows array ([0] => 'V0', [1] => 'V1') Print_R ($ r2-> fields); # shows array (['col1'] => 'V0' ['col2'] => 'V1') -------------------------------------- ------------------------------------------ If you want to get the record number, you can Use $ RecordSet-> RecordCount (). Returns -1 if there is no current record.

Example 2: Advanced SELECT WITH FIELD OBJECTS Search Table, display the first two fields. If the second field is time or date format, it will be changed to the US standard time format display. PHP code: -------- -------------------------------------------------- ---------------------- pConnect ('northwind'); // Connect the MS-Access database named Northwind $ RecordSet = & $ conn-> execute ('select customerid, orderdate from orderrs'); ///// Search for Customerid and ORDERDATE from ORDERS Table IF (! $ Recordset) Print $ conn-> errormsg (); // If the database search error, display error message Else While (! $ Recordset-> EOF) {$ fld = $ RecordSet-> Fetchfield (1); // assign the second field to $ fld $ type = $ recordset-> metatype ($ fld-> type); // Take a field value format IF ($ TYPE == ' D '|| $ TYPE ==' T ') Print $ RecordSet-> Fields [0].' '. $ Recordset-> Userdate ($ recordset-> fields [1],' m / d / y ').'
'; // If the field format is a date or time shape, it outputs Else Print $ RecordSet-> Fields [0].' '. $ RecordSet-> Fields [1].'
'; // Otherwise output $ RecordSet-> MoveNext (); // point to the next record} $ recordset-> close (); // Optional $ conn-> close (); // Optional?> - -------------------------------------------------- ----- ------------------------ In this example, we check the format of the second field with the fetchfield () function. It returns one containing three Object Name: Field Name: Field Name Type: Fields in its database Max_length: Field maximum length, some databases do not return this value, such as MySQL, this case Max_length value is equal to -1. We use metatype () Transform the field database format into a standard field format C: Character field, it should be displayed under tag. X: Text field, store a relatively large text, generally acting on