http://www.moocky.net/manual/adodb.gb.htm
PHP AdoDB 1.99 Handbook Chinese Translation (TRIPC) Thanks Notes
PHP ADODB 1.99 manuals Chinese Translation Author: Tripc ------------------ ADODB PHP in the database support is very commendable, almost all of the well-known database The system has a corresponding functional group support, and the support is very complete. But unfortunately, each group of database support functions have great differences in the name or number of structures, which makes PHP's system developers will always feel painful when they face the replacement database. Does this question have not a solution? Oh, of course, the answer is the PHP object I want to introduce now. AdoDB provides a complete method and property that allows engineers to control the database system. It is better to remember its function. Because of different database systems, as long as you modify a property value, AdoDB will automatically basis Set the correct PHP function. In addition, up to the database system modification to modify the SQL instruction, your PHP system can be replaced to another in the shortest time. If you write a program, you can properly plan the SQL instruction, then almost. After the above introduction, I believe that you have already understood the function of AdoDB, and the following is a detailed introduction of AdoDB. Get adodb you can get the latest version of AdoDB at http://php.weblogs.com/adoDB. When I wrote this article, the latest version is 1.99 version, copyright pick BSD-style and LGPL double rail system, some words are freeware, no restrictions. But after getting AdoDB, it is best to look at the relevant copyright description and usage, and follow this article to avoid errors. It is quite easy to use AdoDB to use AdoDB. After getting the compressive gear, I suggest that the entire content is solved in the adoDB directory. Then you can use this article and study the example inside, put it in the Test directory inside. Since Adodb attached very complete detailed, the following description of most of the readme.htm from AdoDB, not all content, I have removed some content I don't use, and the version difference description, why writing support ADODB drivers, etc., are unrelated to applications. Want to know the readers of all content or you can go to Readme.htm yourself.
Introduction Characteristic installation starts AdoDB
ADONEWCONNECTION NEWADOCONNECTION Support for Database Learning Manual
Example 1: SELECT Sample 2: Advanced SELECT Example 3: Insert Example 4: Error and RS2HTML Examples 5: MySQL and Menu Example 6: One Connection Two Database Example 7: Generate Update and New SQL Directive Example 8 : Use the next and the next and the previous actual roll-off error handling and PEAR error data set to take the test manual
Adoconnection
Link Database: Connect PConnect execute SQL: Execute CacheExecute SelectLimit CacheSelectLimit Prepare PrepareSP GetOne GetRow generate update / add: GetUpdateSQL GetInsertSQL BLOB: UpdateBlob UpdateClob UpdateBlobFile feed / vol Page: PageExecute CachePageExecute clear: CacheFlush Close Transaction: BeginTrans CommitTrans RollbackTrans extract data: $ ADODB_FETCH_MODE BlankRecordSet string: Concat qstr date: DBDate DBTimeStamp UnixDate UnixTimeStamp "column" Manager: affected_Rows Insert_ID GenID error handling: ErrorMsg ErrorNo data dictionary: MetaDatabases metaTables MetaColumns MetaColumnNames opposition: Bind ADORecordSet take single record (not explain?): fetchRow FetchInto FetchObject FetchNextObject GetRowAssoc fields GetAssoc take all records: GetArray GetRows scroll: move MoveNext MoveFirst MoveLast AbsolutePosition CurrentRow AtFirstPage AtLastPage AbsolutePage menu production: GetMenu GetMenu2 date: UserDate UserTimeStamp UnixDate UnixTimeStamp record information: RecordCount PO_RecordSet field Feed: FieldCount FetchField MetaType clear: Close RS2HTML Public Volume Example Introduction Since PHP's data inventory is not standardized Therefore, we need a group of function libraries or categories to hide the differences between inter-different database functions, allowing us to switch the database very simple, and this is the purpose of AdoDB. Adodb currently supports Mysql, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, PostgreSQL, Frontbase, Interbase (Firebird, and Borland), FoxPro, Access, ADO, and ODBC. AdoDB also has a report of Progress and DB2 through ODBC, and we hope that more people can provide drive interfaces to support more databases. The PHP4 support link change variable (session variables), the user can reach the connection information through AdoDB to achieve real portability and elasticity, relevant usage and information, please refer to the example of AdoDB-session.php. In addition, if you have to write a SQL code with a highly portable, you can also read this article with http://php.weblogs.com/portable_sql. Characteristic
For engineers who are familiar with Windows, AdoDB is easy to use because there are many features in AdoDB and the Microsoft's ADO is very similar. Unlike other PHP library categories, most of them focus on things related to the SELECT directive, while AdoDB provides additional support for INSERTS and UPDATE, and can quickly connect to multiple databases. The method provided by the methods provided, the sum of the strings, the string tag character difference processing (the connection and tag symbols of some database strings and the marker symbols are different) Type control systems are built-in So we can set or describe the same data type like char, text and string in different databases. It is easier to transplant because all programming codes depending on the database are hidden in the rear end, so the user no longer needs logic in the transplant category. Support the PHP4 linking variable, please test adoDB-session.php. Installation First To make sure the PHP version you are using is 4.01pl2 or the subsequent version (because the adoDB uses the request_Once and include_once two functions). Unzip all files to a directory that your web server can access. To test AdoDB you need a database, open TestDatabase.inc.php file, and modify the number of links to suit the database you are using. This program will establish a new information sheet in your database to support our testing and examples. In this way, you have installed it. When you start AdoDB When you want to execute AdoDB, at least two files are to be contained, the first is AdoDb.inc.php, which contains the functions to be used in all database classes. The program code on the database is placed in the adoDB - ????. Inc.php file. For example, to connect a mysql database: include ('/ path / to / set / here / adoDb.inc.php');
$ conn = & adonewconnection ('mysql'); Whenever you need to connect to a database, you must use the Adonnection () function to establish a link. AdonewConnection accepts a selective parameter,
Y / N Mssql client Unix and Windows.Unix install howto. Mysql A MySQL does not support transaction processing Y / N MySQL client Unix and Windows mysqlt or maxsql A MySQL support transaction processing Y / N MySQL client Unix and Windows oci8 A Oracle 8/9 Supports more features than Oracle drivers (for example: Affected_Rows). Before connecting, you may need to match the environment variable ('oracle_home = ...') has two ways to connect, using the server IP or Service Name: PConnect ('Serverip: 1521', 'SCOTT', 'Tiger', 'Service') PConnect ('', 'Scott', 'Tiger', 'TNSName'). Y / N Oracle Client Unix and Windows OCI8PO A Oracle 8/9 Portable Driver Y / N Oracle Client UNIX and Windows ODBC A Standard ODBC with PConnect ('DSN', 'User', 'PWD'). ? Depends on database ODBC Unix and Windows. Unix hints. Odbc_mssql C connection ODBC MSSQL Y / N ODBC Unix and Windows. Odbc_oracle C with ODBC connection ORACLE Y / N ODBC Unix and Windows. Oracle C support the old Oracle 7 client API. does not support $ ADODB_FETCH_MODE. Y / N Oracle client Unix and Windows postgres A PostgreSQL does not support LIMIT command. Y PostgreSQL client Unix and Windows. postgres7 A PostgreSQL support LIMIT and other version 7 functionality Y PostgreSQL client Unix and Windows. sqlanywhere C Sybase SQL Anywhere Y / N SQL Anywhere ODBC Client? Sybase C Sybase. Y / N Sybase Client UNIX and Windows. Unix Hints. The code of the test status bar is as follows: A = Many people have verified and tested, the reliability is the highest. B = Test and used, but there may still have some functions that have not been achieved. C = user-configured or trial driver, may not fully support the functionality of AdoDB. "RecordCount () support or not," refers to whether the recordcount () function will return to the record written acquired with the SELECT directive (not supported when not supporting). If the value of this field appears y / n, it means that when the whole variable $ adoDB_counter = true, this is a mode of mode. It should be noted that if you predict that the record has a lot, it is best to set this value to false, which is turned off this simulation function, because it will take a lot of memory, for quick get it. use. Since this variable is checked at each execution, you can selectively use or not use.
All databases support $ adoDB_Fetch_Mode support AdoDB_Fetch_num (in the field order) and adoDb_fetch_assoc (with the field name), two modes. The value is set to adoDB_FETCH_DEFAULT, which is determined by the functionality of the database, so it does not have portability, and AdoDB_Fetch_both (dual mode access) is also the same. Learning Manual Example 1: SELECT Directive Task: Connect to Access's NorthWind DSN, then display the head in each column. (Northwind Northern Database, DSN set by ODBC, is an Access's Standard Example Database) In this example, we create an Adoconnection object, which represents the link of the database. The connection is initialized by a PConnect function and then continues to connect. When we want to query the database at any time, we call the adoConnection.execute () function, which will return an Adorecordset object. In fact, it is just a indicator pointing to the Fields [] array, the current record, and we use molent () to move between records. Note: Another very useful function SelectLimit does not use in this example, which allows us to limit the displayed data pen.
INCLUDE ('adodb.inc.php'); # a a
$ conn = & adonewconnection ('access'); # 建立 a link
$ conn-> pConnect ('northwind'); # links to MS-Access North San Database
$ RecordSet = & $ conn-> execute ('select * from products ";
IF (! $ recordset)
Print $ conn-> errormsg ();
Else
While (! $ recordset-> EOF) {
Print $ RecordSet-> Fields [0]. ''. $ recordset-> fields [1]. '
'
$ RecordSet-> MoveNext ();
}
$ RecordSet-> Close (); # Selective Execution
$ conn-> close (); #Elective execution
"In this example, $ RecordSet returns a record in the $ RECORDSET-> Fields array, currently pointed to. With the column number index, the start value is 0. We use the MoveNext () function to move to the next record. When the last pen, the EOF property is set to true. When the execute () function performs an error, it will return a false value, not a Recordset object. $ RecordSet-> Fields [] Array is generated by the PHP Database Extension Function Library. Some database expansion function libraries support only by numbered, without supporting the name index. To force the use of the column name index, that is, use a closed array, use the $ adoDb_fetch_mode all-in number to set. When a data set is established by the execute () or the SelectLimit () function, it will be stored and stored in such a setting mode. $ AdoDb_fetch_mode = adodb_fetch_num;
$ r1 = $ db-> execute ('select * from table ";
$ AdoDb_fetch_mode = adoDb_fetch_assoc; $ r2 = $ db-> execute ('select * from table ");
Print_r ($ r1-> fields); # shows array ([0] => 'v0', [1] => 'V1')
Print_r ($ r2-> fields); # shows array (['col1'] => 'V0', ['COL2'] => 'V1') The above example statement, if you want to access the field in order, Set the value of $ adoDB_fetch_mode to adoDb_fetch_num, you must set the value to adoDb_fetch_assoc in a closed array (in the field name). To get the number of records selected, you can use $ RecordSet-> RecordCount () method. Note that if you cannot determine the number of recorded records, -1 will be returned. Example 2: Advanced SELECT Directive (Using the Field Item) Task: Select a data sheet to display the front bin. If the second column is a date or time type field, it format it into a US format.
INCLUDE ('adoDb.inc.php');
$ conn = & adonewconnection ('access ");
$ conn-> pconnect ('northwind');
$ RecordSet = & $ conn-> execute ('select customerid, orderdate from orderers ";
IF (! $ recordset)
Print $ conn-> errormsg ();
Else
While (! $ recordset-> EOF) {
$ fld = $ recordset-> fetchfield (1);
$ TYPE = $ recordset-> Mettype ($ fld-> type);
IF ($ TYPE == 'D' || $ type == 't')
Print $ RecordSet-> Fields [0]. ''.
$ RecordSet-> Userdate ($ RecordSet-> Fields [1], 'm / d / y'). '
';
Else
Print $ RecordSet-> Fields [0]. ''. $ recordset-> fields [1]. '
'
$ RecordSet-> MoveNext ();
}
$ RecordSet-> Close (); #boptional
$ conn-> close (); #boptional
> In this example, we use the fetchfield () function to check the data type of the second field. This will return a piece of item that at least three fields, and the column describes the following:
Name: Maitudi TYPE: The data of the field is native model Native FIELD TYPE OF Column Max_length: The maximum length of the field, partial data library is mysql, does not return the correct value of the field, in this example, It will pass back. Then we use metatype () to convert the original type of universal type, the current universal type is defined as follows: C: Character field, you should use the tag to take the value. X: Text, long text field, use the
Include ('adoDb.inc.php'); # loading code Common to adoDB
$ conn = & adonewconnection ('access'); # create a connection
$ conn-> pconnect ('northwind'); # connect to MS-Access, Northwind DSN
$ shipto = $ conn-> qstr ("John's Old Shoppe);
$ SQL = "INSERT INTO Orders (Customerid, Employeeid, OrderDate, ShipName";
$ SQL. = "VALUES ('AnaTr', 2,". $ conn-> dbdate (time ()). ", $ shipto";
IF ($ conn-> execute ($ sql) === false) {
Print 'Error Inserting:'. $ conn-> errormsg (). '
';
}
?> In this example, we saw the process of adding a further date and punctuation symbol. UNIX date Time Narcore (long integer) is formatted into an Access () format to Acceity, and John's Old Shoppe with an abbreviation symbol is processed by the QSTR () function to the John ''s Old Shoppe string to be represented by the database. Legal access. Observe the error handling of the Execute command. If Execute () is executed, the false value is returned when there is an error. The last error message can be displayed by ErrorMSG (). Announcement: The PHP_TRACK_ERRORS flag can be activated to store the error message. Example 4: Error
Include ('adodb.inc.php'); # loading code common to adoDB $ conn = & adonewconnection ('access "); # create a connection
$ conn-> pconnect ('northwind'); # connect to MS-Access, Northwind DSN
$ shipto = $ conn-> qstr ("John's Old Shoppe);
$ SQL = "INSERT INTO Orders (Customerid, Employeeid, OrderDate, ShipName";
$ SQL. = "VALUES ('AnaTr', 2,". $ conn-> formatdate (time ()). ", $ shipto";
$ conn-> debug = true;
IF ($ conn-> execute ($ SQL) === false) Print 'Error Inserting';
>> In the example above, we start the defect mode by setting debug = true. This will display the SQL command before executing the instruction, and all error messages are displayed without call ErrorMSG (). The part of the display is displayed, and the RS2HTML () example can be taken. Others please test the description of the custom error handling. Example 5: MySQL and menu links to the MySQL Database Agora, and create a
Include ('adoDb.inc.php'); # loading code Common to adoDB
$ conn = & adonewconnection ('mysql'); # CREATE A Connection
$ conn-> PConnect ('localhost', 'userid', ',' agora '); # connect to mysql, agora db
$ SQL = 'Select Customername, Customerid from Customers';
$ r = $ conn-> execute ($ sql);
Print $ RS-> GetMenu ('getcust', 'Mary Rosli');
?.> Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected See GetMenu () We also have functions that return the recordset as an array:. GetArray (), and as an associative array with the key being THE FIRST Column: getassoc (). Here, we define a menu named getCust, the preset value is 'Mary Rosli'. Please refer to GetMenu (). We also write data sets in the GetArray () method in the way in array. In addition, the method of retroating the correlation array is used using getAssoc (), where the first field is the key value of this field. In the ADODB after version 1.50, it is the use of public variable $ adoDB_FETCH_MODE to set the return of the return to the number or off-single string. Sample 6: Two Data Library at a time Include ('adoDb.inc.php'); # a a a
$ conn1 = & adonewconnection ('mysql'); #070
$ conn2 = & adonewconnection ('oracle'); #770705
$ conn1-> PConnect ($ Server, $ Userid, $ Password, $ Database);
$ conn2-> PConnect (False, $ Ora_Userid, $ ORA_PWD, $ TNSNAME);
$ conn1-> execute ('INSERT ...');
$ conn2-> execute ('update ...');
?> Sample 7: Generates the SQL Directive of Update and Insert, adds two data set functions: getUpdatesql () and getInsertsql (). This allows you to create a $ rs-> fields replica, change these fields, change these fields, then automatically generate newly updated or new SQL instruction. The following we show how to use these functions, we will access a data sheet with the following fields: (id, firstname, lastname, created). Before these functions are executed, you need to initialize a data set by a query command (SELECT) for the data sheet.
# =============================================== # GetUpdatesql () and getInsertsql () paradigm # ======================================== ====== Include ('adoDb.inc.php'); include ('tohtml.inc.php'); # ====================== ===== # The following program code test new state $ SQL = "SELECT * from adoxyz where id = -1"; # 从 资 资 中 中 空 资 资 集 $ conn = & adonewconnection ("mysql") #021; $ conn-> pconnect ("localhost", "admin", "" "); # # 到 ms,, the database name is Test $ = $ conn -> EXECUTE ($ SQL); # execute the query and get an empty data set $ record = array (); # Initialize an array to store record information for new-added # set records in the field value in the record $ Record ["firstname"] = "bob"; $ record ["lastname"] = "smith"; $ record ["created"] = time (); # Introduction Empty data set and field data array to getInsertsql functions To execute the function # This function will return to a full format Insert SQL instruction $ INSERTSSERTSQL = $ conn-> GetInsertsql ($ RS, $ Record); $ conn-> execute ($ INSERTSQL); # = ========================================================== # 以下 程 = = "SELECT * FROM ADOXYZ WHERE ID = 1 "; # Select a record to update $ RS = $ conn-> execute ($ SQL); # execute this query and get an existing record to update $ Record = array ();
# Initialize an array to save the information you want to update # $ record ["firstname"] = "caroline"; $ record ["Lastname"] = "smith"; # 更 l l l "] =" smith "; # Update Caroline's surname by Miranda Change SMITH # Incoming that only single recorded data sets, and data-containing arrays to getUpdateSQL functions # functions will return a Update with correct WHERE condition (update) SQL instruction $ updatesql = $ conn-> getUpdatesql ($) RS, $ Record; $ conn> execute ($ updatesql); # Update Database Record $ conn-> close ();?> Example 8: Using Previous and Next Practical Rolling We use HTTP gets $ next_page variable to track the page to jump to the page and save the current page number in the session variable $ curr_page. We call the pageExecute () letter of the link to get our data set, and then we use the data set atfirstPage () and atlastPage () function to decide whether to display the next page and the previous button. phpinclude_once ('adoDb.inc.php');
INCLUDE_ONCE ('tohtml.inc.php');
Session_register ('curr_page');
$ db = newadoconnection ('mysql');
$ DB-> Connect ('localhost', 'root', '', 'xphplens');
$ NUM_OF_ROWS_PER_PAGE = 10;
$ SQL = 'SELECT * from Products';
IF (isset ($ http_get_vars ['next_page'])))
$ curr_page = $ http_get_vars ['next_page'];
IF (EMPTY ($ curr_page)) $ curr_page = 1; ## at first Page
$ r = $ db-> pageexecute ($ SQL, $ NUM_OF_ROWS_PER_PAGE, $ CURR_PAGE);
IF (! $ r) DIE ('query failed');
IF && (! $ r-> atfirstpage () ||! $ r -> atlastpage ()) {
IF (! $ r-> atfirstpage ()) {
?>
PHP
}
RS2HTML ($ RS);
}
?> The above program code can be found in TestPaging.php paradigm. Use custom error handling and pear_error in previous versions, you can use like $ con-> debug = true; this setting is made. But after the 1.50 version, we provide another way to handle the wrong status. We allow engineers to use AdoDB's self-binding error handler. AdoDB provides two kinds of customization, you can be revised with your needs. The first method is placed in the AdoDB-Errorhandler.inc.php file. This allows you to use standard PHP function err_reporting to control what error message to display and Trigger_Error went to call the PHP preset error handler. After introducing the above file (AdoDB-Errorhandler.inc.php), after the following errors have occurred, Trigger_ERROR ($ ERRORSTRING, E_USER_ERROR) will be called. When Connect () or PConnect () is executed. If the function of performing the SQL instruction fails, such as execute () or selectlimin (). GenID () entered an infinite loop. The $ ErrorString variable here is generated by AdoDB. And it will contain useful amplifies messages, similar to the Error.log data that will be established. So, in order to properly provide an extension message, you have to introduce AdoDB-Errorhandler.inc.php in front of the Adoconnection object. If you define error_reporting (0), no errors will be shown. If you set error_reporting (e_all), all errors will be displayed on the screen. If you set an error_reporting (0), there will be no error will be displayed. . If you set ERROR_REPORTING (E_ALL), all error messages will be displayed. The following is a simple example: PHP
Error_Reporting (E_ALL); # Display all error messages
Include ('AdoDB-Errorhandler.inc.php');
INCLUDE ('adoDb.inc.php');
INCLUDE ('tohtml.inc.php');
$ c = newadoconnection ('mysql');
$ C-> PConnect ('localhost', 'root', '', 'northwind');
$ r = $ c-> execute ('select * from productsz'); # incorrect data table productsz ');
IF ($ RS) $ RS2HTML ($ RS);
?> If you want to record the error message, you can define two selective constants adoDB_ERROR_LOG_TYPE, AdoDB_ERROR_LOG_DEST. For the value of adoDb_error_log_type, you can go to the PHP User Manual for an instructions for ERROR_LOG. In the following example, I set it to 3, meaning that the message records the message to the file set by the constant adoDB_ERROR_LOG_DEST. PHP
Error_reporting (0); # does not display any error message
Define ('adoDb_error_log_type ", 3);
Define ('adoDb_error_log_dest'; 'c: /errors.log'); include ('adoDb-errorhandler.inc.php');
INCLUDE ('adoDb.inc.php');
INCLUDE ('tohtml.inc.php');
$ c = newadoconnection ('mysql');
$ C-> PConnect ('localhost', 'root', '', 'northwind');
$ r = $ c-> execute ('select * from productsz'); ## incorrect information list Productsz
IF ($ RS) $ RS2HTML ($ RS);
?> The following is an error message written in an Error.log file: (2001-10-28 14:20:38) mysql error: [1146: table 'northwind.productsz' doesn't exist] in
Execute ("Select * from Productsz") The second error handling method is AdoDB-Errorpear.inc.php. Using this method, a pear_error derivative object is generated during error occurs, and the final generated Pear_ERROR object can be retrieved by the AdoDB_Pear_ERRIR () function. PHP
Include ('AdoDB-Errorpear.inc.php');
INCLUDE ('adoDb.inc.php');
INCLUDE ('tohtml.inc.php');
$ c = newadoconnection ('mysql');
$ C-> PConnect ('localhost', 'root', '', 'northwind');
$ r = $ c-> execute ('select * from productsz'); # incorrect data table productsz ');
IF ($ RS) $ RS2HTML ($ RS);
Else {
$ E = adoDb_pear_error ();
Echo '
', $ E-> Message (), ' p>';
}
?> Before introducing AdoDB-ERRORPEAR.INC.PHP file, you can use a pear_error derivative category by defining the adoDb_pear_error_class constant. For convenience, you can define the preset error mode in the PHP program code for pear_error_die, which will make the program error, and immediately output the error message and stop execution. INCLUDE ('pear.php');
Pear :: seterrorhandling ('pear_error_die'); Note that when the error is generated, AdoDB does not clearly return a pear_error object to you. You must need to call the AdoDB_pear_Error () function to retrieve the last error. Or, you can use Pear_Error_die this skill. The data set is now, and AdoDB uses cacheeexecute (), cachepageexecute () and cacheselectrlimit () functions to support the data set. Usage is similar to a function that does not take it, except for a new number $ SECS2CACHE. The following is an example: include ('adoDb.inc.php'); # loads Adodb $ adoDb_cache_dir = '/ usr / adoDb_cache';
$ conn = & adonewconnection ('mysql'); # 建 立
$ conn-> pConnect ('localhost', 'userid', ',' agora '); # links to MySQL, Agora Database
$ SQL = 'Select Customername, Customerid from Customers';
$ r = $ conn-> cacheexecute (15, $ sql); the first number is the number of quick time to set the query. The query of the subsequent call will be stored using the quick data specified by the $ adoDb_cache_dir variable. To force the verification execution, and update the recording, use the cacheexecute () function, and set the first number to 0. Or, use Cacheflush ($ SQL). Based on security considerations, if you want to use $ adoDB_Cache_Dir, we recommend that you will be set to OFF in the php.ini. After the AdoDB version 1.80, in cacheselectrlimit () and cacheexecute (), the number of secondcache is selective. If you don't fill it, the system will use the value of the $ connection-> cachesecs property, and its preset is 60 minutes. $ conn-> connect (...);
$ conn-> cachesecs = 3600 * 24; // Take 24 hours
$ r = $ conn-> cacheexecute ('select * from table ";
The number of 考 手 手 数 数 数 数 数 数 数..... Shared variable $ adodb_countrecs When this variable ($ adoDb_countrecs) is set to true, if the database driver program interface (API) does not support the number of data selected by the SELECT instruction, then the recordcount () function will automatically simulate. And return to the correct data pen, the preset value is TRUE. The simulation method is to establish a memory temporary area to place these information, so when the number of materials retrieved is large, it will occupy a lot of memory. When setting this variable value is false, there will be the best performance. This variable will be automatically checked when each execution is executed, so you can act before each query is required. $ AdoDB_cache_dir If you use the information set to get the function, then those who are taking the information will be placed in the directory specified in this variable. So when you want to use the function, you should set this variable before you use the function. Exception in security, if you want to use $ adoDB_cache_dir, we recommend that you will be set to OFF in the PHP.INI's Register_Globals. $ AdoDb_fetch_mode This shared variable determines that the data set will pass the data to the array. The data set is saved when it is established (such as Execute () or selectLimit ()) saves this variable ($ addb_fetch_mode), and any change in this variable ($ adoDb_fetch_mode will not affect existing information set) Only when the data set is established in the future. The following is for the defined constant: define ('adoDb_fetch_num', 0); define ('adoDb_fetch_assoc', 2); define ('adodb_fetch_both', 3); the following is an example of using : $ AdoDb_fetch_mode = adoDb_fetch_num; $ r1 = $ db-> execute ('select * from table ";
$ AdoDB_Fetch_mode = adoDb_fetch_assoc;
$ r2 = $ db-> execute ('select * from table ";
Print_R ($ r1-> fields); # Display Array ([0] => 'V0', [1] => 'V1')
Print_r ($ r2-> fields); # Display Array (['COL1'] => 'V0', ['COL2'] => 'V1') In this example, if you see two data set When Execute () is established, the storage and use of the access mode will be determined according to the value of $ adoDB_ferch_mode. If no mode is set, the preset value is adoDB_FETCH_DEFAULT. The presented mode varies depending on the database driver. For portability, we recommend that you are fixed to adoDb_fetch_num and adoDb_fetch_assoc, because there are many drivers that do not support adodb_fetch_both.
AdoConnection provides a link to the file, performing SQL instructions, and a set of items such as SQL related functions. Adoconnection Attribute DatabaseType: The name of the database to be connected, such as ODBC, MSSQL, MySQL, etc. Please refer to the table for details. DataProvider: The underlying Database Subsequency, in addition to using ODBC or ADO, it is generally set to native. Host: Database host name, available with IP or Source Name (DSN). Such as 203.74.225.22, dbs1.nukepro.com, "localhost", "odbc_dsn1" Database: Database or link name, if ADO is used, the ADO data is controlled to provide a driver (ADO DATA Provider). User: The ID at the time of login, the password is not reserved based on the safety consideration. RaiseErrorfn: Allows you to define an error handling function, please test the example of AdoDB-Errorhandler.inc.php. Debug: When it is set to True, the extent is displayed. Concat_operator: Connect the operation calculation element, usually set to ' ' or '||'. This computational element is in order to connect strings in SQL. Will be used in the Concat function. FMTDATE: Date format, used in the dbdate function, as a basis for sending date information to the database. In the Access format is '# Y-m-d #', in the MySQL format "/ y-m-d /". FMTTimeSTAMP: Time format, you want to send time information in the DBTimeStamp function to the database. True: The performance of the real value in the information, such as using 't', MS SQL in FoxPro, '1'. FALSE: The way the value is fashionable, such as 'f', MS SQL with '0' in FoxPro. ReplaceQuote: This string is used to handle the escape symbol. For example, in the microsoft SQL, double quotes in MySQL, in MySQL. Mainly used in QSTR. AutoCommit: Set whether to start the automatic transaction mode, the preset value is true. Charset: Setting the character set used, currently only Interbase support. MetataBless QL: Use SQL instructions to return to a list of available data sheets. For example, SHOW TABLES in MySQL. Genid: If the database has supported, it will be stored here to the final value obtained by GetId (). Cachesecs: Quickly take the number of seconds. Used to use the cacheeexecute () or cacheseletlimit () function, there is no preset value when the $ SECS2CACHE number is set. Sysdate: Use the database function to get the current date and time. Will use the native datetime tag format.
AdoConnection Main Functions AdoConnection () Constructs a function, please do not call directly, use AdonEwconnection () instead. Connect ($ Host, [$ User], [$ Password], [$ Database]) For the server or data source $ host non-sustainability, the user authentication code is $ user, the password is $ password if the server support Multi-database, specify a link to the database $ database. Successfully returns TRUE, followed by FALSE. Note: If you are using Microsoft ADO, not OLEDB, you can set a $ database number for the OLEDB data supplier you are using. PostgreSQL: Another selective linking method is to put the standard PostgreSQL loop string in the $ Host number, then the number of other numbers will be saved. For Oracle and OCI8, there are two ways to connect. First, use the TNS name in the area TNSNames.ora, put this name in the $ database number, then set the $ host to false. Alternatively, set $ host as a server, and $ Database set into a database SID, which will not link through the TNSNames. ORA. Example: $ conn-> connect (false, 'scott', 'tiger', 'name_in_tnsnames'); # Using TNSNAMES.ORA $ Conn-> Connect (' Server: 1521 ',' Scott ',' Tiger ',' ORACLESID '); # Do not use TNSNames.raa and many database link examples on the website php.weblogs.com/adoDB and in the TestDatabase.inc.php file attached to this version. PConnect ($ Host, [$ User], [$ Password], [$ Database]) Connect the server or data source $ host, the user authentication code is $ user, the password is $ Password if the server supports more The database is specified to link to the database $ database. Successfully returns TRUE, followed by FALSE. Please refer to Connect (). Execute ($ SQL, $ INPUTARR = FALSE) Performs SQL Directive $ SQL, if successful, return to a corresponding Adorecordset object. Note that this command will definitely return to a data set if it is executed, even if it is executed in Insert or Update instructions. Back to the corresponding adorecordset object. For example, if the connection is mysql, then adorecordset_mysql will be passed back. The FALSE value will be returned when the SQL instruction failed. The $ INPUTARR number is used as a combination of incoming combination. The following is an example of Oracle: $ conn-> execute ("SELECT * from Table Where Cond =: Val", Array ('Val' => $ VAL);
Another example, use ODBC, as an agreement with '?' Symbol. $ conn-> execute ("SELECT * FROM TABLE WHERE COND =?", Array ($ VAL)); Binding Variables) variables can accelerate SQL instructions to compile and express speeds, resulting in better performance. There is currently only Oracle and ODBC support variables. The ODBC class is in a database that is not supported, it is done in analog. The variable combines the usage in the ODBC and OCI8PO drivers. $ r = $ db-> execute ('select * from table where val =?', array ('10 ')); the variable combines the usage in the OCI8 driver. $ r = $ db-> execute ('select name from table where val =: key ", array (' key '=> 10)); Cacheexecute ($ secs2cache, $ sql, $ intrutarr = false) is similar to the Execute function, In addition to temporarily except for the directory specified by $ adoDb_cache_dir, $ Secs2Cache seconds. If cacheexecute () is used by the same number, the database, the user ID and password, and there is no expiration, the data set in the quick tap will be returned. Include ('AdoDb.inc.php'); include ('tohtml.inc.php');
$ AdoDB_cache_dir = '/ usr / local / adodbcache';
$ conn = & adoleconnection ('mysql');
$ conn-> pConnect ('localhost', 'userid', 'password', 'database');
$ r = $ conn-> cacheexecute (15, 'select * from table'); #Tet 15 seconds
RS2HTML ($ RS); / * RecordSet to html table * / In addition, from the ADODB 1.80 version, $ secs2cache parameter becomes selective (not add) $ conn-> connect-> connect (...);
$ conn-> cachesecs = 3600 * 24; // cache 24 Hours
$ RS = $ conn-> cacheexecute ('select * from table "); if cacheexecute () is called multiple times, and the data set continues to get it quickly, $ SECS2CACHE number will not extend the base set of information to be retained Time (because it will be saved), cacheexecute () can only be used on the SELECT instruction. Effective Note: I have made some effective tests and found that these quick access is extremely significant. Especially when the operational efficiency of the database server is slower than the load of the web server or the database. AdoDB is getting better in it reduces the load of the database server. Of course, if your database server is not large, and the speed is faster than the web server, it will reduce the performance. SELECTLIMIT ($ SQL, $ NumRows = -1, $ OFFSET = -1, $ INPUTARR = FALSE) Perform success will return a profile. Complete a SELECT directive, similar to the Limit $ Numrows Offset $ OFFSET in the SELECT instruction in PostgreSQL. In PostgreSQL, SELECT * from Table Limit 3 will only pass the three records starting from the beginning. The same, $ connection-> selectlimit ('Select * from Table', 3) also has the same meaning. SELECT * from Table Limit 3 Offset 2 will return to record 3, 4 and 5 (after recording 2, return three records). Similarly, in the adoDB is made in $ connection-> selectlimit ('select * from table', 3, 2). Be careful, LIMIT declares, in the opposite position in MySQL. You can set a record of $ connect-> selectlimit ('Select * from Table', - 1, 10) to get the record from the 11th to the last one. The last parameter $ INPUTARR is a database that supports variable binding functions, like Oracle OCI8. This greatly reduces the load of SQL compilation. Under the Oracle Example: $ conn-> selectlimit ("Select * from table where cond =: val", 100, -1, array ('val' => $ val)); Oracle Portable Driver is more For standard variables: $ conn-> selectlimit ("SELECT * from Table Where Cond =?", 100, -1, Array ('Val' => $ VAL)); RON Wilson reported SELECTLIMIT included in SQL instructions Union will be invalid, and it is recommended that the countermeasures for MSSQL:> In fact, I found a SELECT UNION method that can be optimized immediately. This applies to MS-SQL, as for
Whether other databases are suitable, it is uncertain. You can take this example when you update your assignment. Attention, this party
The law does not apply to MySQL.
>
> Change:
> SELECT Column1 from Table1
> Union
> SELECT Column2 from Table2
>
> Become:
> SELECT * FROM
> SELECT Column1 from Table1
> Union
> SELECT Column2 from Table2
>)
> As DummyTable
>
> Ron Cacheselectrlimit ($ 42Cache, $ SQL, $ NumRows = -1, $ OFFSET = -1, $ INPUTARR = FALSE) is similar to SelectLimit, except for the collection of information set in the directory specified by $ adoDB_cache_dir. From the 1.80 version, $ Secs2Cache became the selective parameter: $ conn-> connect (...);
$ conn-> cachesecs = 3600 * 24; // Take 24 hours
$ RS = $ conn-> cacheselectrlimit ('select * from table "; cacheflush ($ SQL) update (delete) Store all the quick-tanks in $ adoDb_cache_dir specified in $ adoDb_cache_dir in $ SQL instruction. If you try to update all the quick-tank data set, perform the following PHP instruction code (valid only for UNIX): System ("rm -f find" .adodb_cach_dod. "-Name adodb _ *. Cache"); errormsg () back Transfer the last state or an error message. Even if there is no error, this function will return a string. Under normal circumstances, you don't need to call this function unless the ADODB function returns a false value because the error status is returned. Note: If the debug flag is started, the SQL error message will appear after an error occurs when the Execute function is called. ErrorNO () returns the last error number. Pay attention to a little, the old version of PHP (4.0.6) does not support the ODBC's error number. Under normal circumstances, you don't need to call this function unless the ADODB function returns a false value because the error status is returned. GenID ($ SEQNAME = 'AdoDBSeq', $ STARTID = 1) Generates a sequential number (in MSSQL is an integer value). For Interbase, MySQL, PostgreSQL, OCI8, OCI8PO, ODBC core drive program (such as Access, VFP, DB2, etc.) support. Use $ SEQNAME as a sequence name. If the database does not have a value, then genid () will automatically generate a serial number (so that the user ID is generated), in other words, you must establish a serial number yourself. If your database driver wants to simulate the serial number, the name of the data sheet is the sequence name, and this information table must have a field "ID", and its data type is an integer, or you need more Numeric (16). For ODBCs and databases (such as MSSQL, MySQL) without support serial number, we create a data sheet for each serial number. If the serial number is not pre-defined, the value is set to $ startID. Note that the GenID () of the MSSQL driver will generate a 16-bit GUID. From the 1.90 version, we will return the integer. UpdateBlob ($ TABLE, $ Column, $ VAL, $ Where) Allows you to store a BLOB (there is $ VAL) value to $ COLUMN field in $ where conditions. Example: # for oracle
$ conn-> execute ('INSERT INTO BLOBTABLE (ID, blobcol) VALUES (1, EMPTY_BLOB ()));
$ conn-> updateblob ('blobtable', 'blobcol', $ blobvalue, 'id = 1'); # non Oracle Databases
$ conn-> execute ('INSERT INTO BLOBTABLE (ID, Blobcol) VALUES (1, NULL)');
$ conn-> UpdateBlob ('blobtable', 'blobcol', $ blobvalue, 'id = 1'); if success, return True, otherwise return false value. There are currently mysql, postgreSQL, OCI8, OCI8PO, and Interbase support. Other drivers may be valid and remain in continuous development. Be careful, in the previous version of PHP 4.1.0, when Interbase's BLOB value is retrieved by SELECT, it still needs to be decoded, please use $ connection-> decodeblob ($ bl); restore its content. UpdateClob ($ TABLE, $ Column, $ VAL, $ Where) Allows you to store a $ where condition to $ Column fields in $ TABLE. Similar to UpdateBlog, but mainly for text large archive objects. Example: # for oracle
$ conn-> execute ('INSERT INTO Clobtable (ID, Clobcol) VALUES (1, EMPTY_CLOB ());
$ conn-> updateblob ('clobtable', 'clobcol', $ clobvalue, 'id = 1');
# Non Oracle Databases
$ conn-> execute ('INSERT INTO CLOBTABLE (ID, Clobcol) VALUES (1, NULL)');
$ conn-> UpdateBlob ('Clobtable', 'Clobcol', $ ClobValue, 'ID = 1'); UpdateBlobfile ($ TABLE, $ Column, $ PATH, $ Where, $ blobtype = 'blob') like UpdateBlob, but we Change the value to a file path to deposit the entire file. Successful Recycling True Otherwise, False. GetUpdateSQL (& $ RS, $ Arrfields, $ forceUpdate = false, $ magicq = false) Create a SQL to update a given data set $ r, modified fields in array $ arrfields (this array must be named Array, column name is index, the value is a correction value), will make a comparison with the original data set, if $ forceUpdate is set to True, even if $ arfields is exactly the same as $ r-> Fields, will also be updated SQL instructions. The data set must be in the connection state. $ MAGICQ is used to indicate whether the magic quotation number function is started. GetInsertsql (& $ RS, $ Arrfields, $ Magicq = False) establishes a SQL to add a new record to the obtained data set $ RS. This query must be in a link state. $ MAGICQ is used to indicate whether the magic quotation number function is started. Pageexecute ($ SQL, $ NROWS, $ PAGE, $ INPUTARR = FALSE) Using the page number feature of the data set, the number of 叁 Page is 1 to set the value, please take an example 8. Cachepageexecute ($ SECS2CACHE, $ SQL, $ NROWS, $ PAGE, $ INPUTARR = FALSE) Use the page number function of the data set, and the number $ Page is 1 to set the value, please test the Quick Edition of the paragrace 8.pageexecute. Close () Close the connection of the database. PHP4 has a presence of special removal at the end of the database connection, because the counting mechanism will automatically help us clear. Begintrans () begins a transaction. The automatic check function will be turned off. The execution will return to TRUE. If the trading function is not supported, the partial database will pass back the false value. Interbase, Oracle and MSSQL Support Trading Mechanism. Please note that because the PHP 4.02 is bug, the transaction support is invalid on Microsoft's ADO. You must use the native transaction support feature of your custom database. Any open transaction will be restored when the connection ends. CommitTrans () successfully ended a transaction. If successful, return to True. If the database does not support the transaction function, it will only pass True to indicate that the information is always transaction. RollbackTrans () ends a transaction and restores all changes. The execution will return to TRUE. If the database does not support the transaction function, it will only pass false to indicate that the information can always be recovered. GetOne ($ sql) Executes the SQL and returns the first field of the first row as an array. The recordset and remaining rows are discarded for you automatically. If an error occur, false is returned. Execute SQL, and in an array Back to the first column of the first record. The data set and its own record will be automatically cleared. If an error occurs, it will return the false value.
Translator Note: This feature verifies that a record is not particularly useful, which can reduce the amount of system memory and resources. GETROW ($ SQL) executes the SQL instruction and pass the first record in an array. The data set and its own record will be automatically cleared. If an error occurs, it will return the false value. Prepare ($ SQL) is pre-compiled a SQL query to make you overcome. If there is any syntax error, prepare () does not display an array of errors, but allows Execute () to obtain and display errors. Internal work support Interbase, OCI8, and selective ODBC-Based drivers. The rest is supported by simulation. In the case of simulation, there is no effect using prepare () to increase efficiency. Back to a array containing the original description as the first array element, the content of the elements is determined by the driver. If there is an error or analog way preted (), it will return to the original $ SQL string. That's because all the error handles are concentrated in Execute (). Example: $ stmt = $ db-> prepare ('INSERT INTO TABLE (COL1, COL2) VALUES (?,?)'); For ($ I = 0; $ i $ DB-> EXECUTE ($ Stmt, Array ((String) Rand (), $ I)); preplesp ($ SQL) In the MSSQL driver, the precompiled pre-lamination must call MSSQL_Init through a special function. () This action is currently handled by this function. PrepareSP () can be simulated by all drive programs, and simulated in a call preted (). Use an example, please examine the following parameter (). The same array or $ SQL string is passed back to the preord (). Parameter ($ STMT, $ VAR, $ Name, $ ISOUTPUT = FALSE, $ MAXLEN = 4000, $ TY = FALSE) Add a binding number in operation. It is currently compatible with Microsoft SQL and Oracle OCI8. The following is a number of parameters: $ STMT is passed from prepare () or preord (). $ VAR to be a PHP variable. $ Name to be combined with the change name of the pre-stored program. [$ ISOUTPUT] Set the direction of the number of passages, 0 / false = in 1 = OUT 2 = IN / OUT. This parameter in OCI8 will be ignored because the driver will automatically detect. [$ MAXLEN] The maximum length of the number variable. [$ TYPE] 考 MSSQL_BIND and OCIBINDBYNAME in PHP.NET file instructions to achieve more correct values. In MSSQL, $ OPT can be affected by the following elements: MSSQL_BIND AND OCIBINDBYNAME. For example; # @retval = sp_runsomething@myid, @ group $ STMT = $ dB-> prepareSp ('sp_runsomething "; # Note That the parameter name does not have @ in front! $ DB-> Parameter ($ STMT, $ ID, 'MyID'); $ DB-> Parameter ($ STMT, $ Group, 'Group', False, 64); # Return Value In Mssql - Retval IS HARD-CODED NAME $ DB-> Parameter ($ STMT, $ RET, 'RETVAL', TRUE); $ DB-> EXECUTE ($ STMT); an option: # for Oracle, Prepare and Preparesp is the same $ STMT = $ db-> preparesp DECLARE RET Integer; Begin : Retval: = sp_runsomething (: myid,: group); End; "); $ DB-> Parameter ($ STMT, $ ID, 'MyID'); $ DB-> Parameter ($ STMT, $ Group, 'Group', False, 64); $ DB-> Parameter ($ STMT, $ RET, 'RETVAL', TRUE); $ DB-> Execute ($ STMT); Please note that only the syntax between OCI8 and MSSQL is different, that is, the database is actually SQL syntax problem, and AdoDB is in powerless. If the $ TYPE number is set to false. In MSSQL, $ TYPE will dynamically pass the type of PHP variable (String => sqlChar, Boolean => SQLINT1, INTEGER => SQLINT4 or FLOAT / DOUBLE => SQLFLT8), in OCI8, $ TYPE can be set Enable oci_b_file (binary-file), OCI_B_CFile (Character-file), OCI_B_Clob (Character-LOB), OCI_B_Blob (Binary-Lob) and OCI_B_Rowid (RowID). If you want to pass null, use $ db-> parameter ($ STMT, $ null = null, 'param'). Finally, in OCI8, the binding number can be re-covered without call preord () or parameters. But this is not possible to MSSQL. The example of an OCI8 is as follows: $ ID = 0; $ i = 0; $ STMT = $ db-> preparesp ("Update Table Set Val =: I where id =: id"); $ DB-> Parameter ($ STMT, $ ID, 'ID'); $ DB-> Parameter ($ STMT, $ I, 'I'); For ($ CNT = 0; $ CNT <1000; $ CNT ) { $ ID = $ CNT; $ I = $ CNT * $ CNT; # oci8 can operate $ db-> execute ($ STMT); } Bind ($ STMT, $ VAR, $ SIZE = 4001, $ TYPE = FALSE, $ Name = false) This is a low-order function, only OCI8 driver support. Only if you determine that the system only supports Oracle, please avoid using it. The parameter () function is another recommended way to use the combination variable. Bind () allows you to use a combination variable in your SQL description. Here, a PHP variable is given to a name defined in the Oracle SQL description predefined by prepare (). Oracle is named a variable with a colon, and AdoDB requires a named variable to correspond to: 0,: 1,: 2,: 3, etc. The first time by bind () will be substituted: 0, and the second time will be substituted: 1, so on. For INSERT, SELECT, and UPDATE instructions, the combination can provide 100% effectiveness. In its random number, $ size setting the tip size size, $ TYPE is OCI_B_File (Binary-file), OCI_B_CFile (Character-Lob), OCI_B_Clob (Binary-Lob) And the category option for OCI_B_ROWID (RowID). Finally, instead of using the preset: 0,: 1, etc., you can use $ name to define your own link name. The next example shows 3 links, using P1, P2, and P3 to bind. These variables will be distributed to: 0,: 1 and: 2. $ stmt = $ db-> prepare ("INSERT INTO TABLE (COL0, COL1, COL2) VALUES (: 0,: 1,: 2)"); $ db-> bind ($ STMT, $ P1); $ Db-> bind ($ STMT, $ P2); $ Db-> bind ($ STMT, $ P3); For ($ I = 0; $ i <$ max; $ i ) { $ P1 =?; $ P2 =?; $ P3 =?; $ Db-> execute ($ STMT); } You can also use name variables: $ stmt = $ db-> prepare ("INSERT INTO TABLE (COL0, COL1, COL2) VALUES (: Name0,: Name1,: Name2)); $ Db-> bind ($ STMT, $ P1, "Name0"); $ Db-> bind ($ STMT, $ P2, "Name1"); $ Db-> bind ($ STMT, $ P3, "Name2"); For ($ I = 0; $ i <$ max; $ i ) { $ P1 =?; $ P2 =?; $ P3 =?; $ Db-> execute ($ STMT); } Adoconnection public function BlankRecordset ([$ queryid]) is no longer used, this version has been removed. Concat ($ S1, $ S2, ....) generates a string combined with $ S1, $ s2, .., using a string of SQL strings, using the combined operation symbol defined in the Concat_operator field. This function will be invalid if the combined operation symbol is not used, that will be invalid, such as MySQL. This function returns a string of combined symbols. DBDATE ($ DATE) Format $ DATE The format that can be received, which can be a UNIX integer time record format or Y-M-D in an ISO format. Use the format defined by the FMTDATE field. If it is incorporated or false or '', it will turn into a SQL NULL. Back to a date string. DBTimeStamp ($ TS) Format Time Record Format The $ TS Available Format. This can be a UNIX integer time record format or Y-m-D in an ISO format. Use the format defined by the FMTDATE field. If it is incorporated or false or '', it will turn into a SQL NULL. Back to a time string. QSTR ($ S, [$ MAGIC_QUOTES_ENABED = false]) Place a string in quotation marks to send it to the database. $ MAGIC_QUOTES_ENABED 叁 may seem fun, but this idea is to assume that you have used a quotation number to handle the string from the POST / GET variable, then be the second number of gs as the second number of GET_MAGIC_QUOTES_GPC (). This will determine that this variable will not be handled twice, once by QSTR, once by Magic_QUOTES_GQC once again. For example: $ s = $ db-> qstr (http_get_vars ['name'], get_magic_quotes_gpc ()); the backup value is a string that is being processed by quotation marks. Affected_rows () back to the number of data written by updating or deleted by SQL instructions. If the database does not support, return to a FALSE value. The interbase / firebird does not support this function. INSERT_ID () Recycling the automatic enhanced value ID of the last insertion. If the system does not support, return false. Only supporting a library that provides automatic promotion or object IDs, currently like PostgreSQL, MySQL, and MSSQL. PostgreSQL returns an OID to change when the database is overloaded. This function will have precise results when you complete a transaction. This is because the links declared by the execute () may differ from the next EXECUTE (). Metadatabases () Back to a library list in the server in the array. First, you must connect to the server. Currently only support ODBC, MySQL and ADO. Metatables () Retrieves all the data table names in the current database in an array. This array will rule out the system directory data sheet. Metacolumns ($ TABLE) returns an array of AdofieldObject, and one field object corresponds to all rows of $ TABLE. At present, Sybase cannot identify the data type, ADO cannot identify the correct data type (so we preset to varchar) .. MetacolumnNames ($ TABLE) Reward $ TABLE is named in an array. AdorecordSet (Data Set) When an ADOCONNECTION-> Execute ($ SQL) is executed after a SQL instruction, an AdorecordSet article will be sent back. This object provides a virtual indicator, so we can move it, from a pen. Some functions are also available to obtain field information and field categories, and have the help function to format the results to show them to the user. AdorecordSet Properties Fields: Contains the current recorded array. Not a closed array, but its index value is from 0 to fields - 1. Please refer to the function fields, this function is like a closed array. DataProvider: The underlying mechanism of the subscription is normally set to Native, unless you use ODBC or ADO. Blobsize: A char, string or varchar object is the maximum length before being converted to blob (textarea should be used when the blob is displayed. Please refer to the Metatype function. SQL: The SQL instruction used in this data set is stored. CANSeek: If the Move () function has a function, it will be set to true. EOF: This value will be set to TRUE when the indicator is moved to the last pen. ADORECORDSET Function AdorecordSet () Constructs a function. Generally speaking, you don't need to call this function. GetAssoc ([$ force_ARRAY]) If the field is greater than 2, a clean array is generated from the data set. This array is from the current indicator until the end (EOF). The first field of this data set will become an index of the array. If the field number is just 2, when this array is established by each key value, the index will directly correspond to the value, unless $ force_array is set to TRUE. Example: The following is our information collection: Column 1: Apple, Fruit, Edible Columns 2: Cactus, Plant, Iundible Columns 3: Rose, Flower, Edible GetAssociation will generate a related array: Apple => [Fruit EDIBLE] CACTUS => [Plant, INEDIBLE] ROSE => [FLOWER, EDIBLE] Recycling value: Off-style array, error is sent back False. GetArray ([$ Number_OF_ROWS] generates an array from the current indicator location, with an index value from 0 to $ Number_OF_ROWS - 1. If $ Number_OF_ROWS is not defined, it will go to the end of the position (EOF). GetRows ([$ Number_OF_ROWS]) is the synonymous function of GetArray (), is to be compatible with Microsoft ADO. GetMenu ($ Name, [$ BLANK1STITEM = true], [$ multiple_select = false], [$ size = 0], [$ moreattr = '']) to create an HTML menu ( If $ default_str is defined, then if $ default_str == Fields [0], then this field will be selected. If $ blank1stitem is True, the first option will be null. $ DEFAULT_STR can be an array when you can select a single box. To generate a single area, set $ size as a non-0 value (or incoming $ default_str as an array). If $ multiple_select is true, then a monitable area will be generated as a menu with a $ size item (if $ size == 0 is 5), and AdoDB will return an array to the server. Finally, you can use $ moreattr to increase other properties, like JavaScript or style sheet. SLR Example 1: GetMenu ('Menu1', 'A', True) will generate a menu like this: ABC information (A, 1), (B, 2), (B, 2), (C, 3), please Example 5. SLR Example 2: The same information, GetMenu ('Menu1', Array ('A', 'B'), FALSE will generate menu: ABC GetMenu2 ($ Name, [$ default_str = ' '], [$ MULTIPLE_SELECT = true], [$ size = 0], [$ moreattr =' ']) approximates GetMenu, except $ default_str, will compare with Fields [1], That is, the option value. SLR Example 3: Give the information in paragrace 2, getMenu2 ('Menu1', Array) will produce a menu, A and B will be selected. However, this time the selected alignment benchmark is the second field, that is, the value stored to be returned to the server. UserDate ($ STR, [$ FMT]) Conversion Date String $ Str is another format, userdate call unixdate to interpret $ STR, and the $ fmt preset value is Y-m-D. UsertimeStamp ($ STR, [$ FMT]) Conversion Time String $ STR is another format, the time string format is Y-m-D h: i: s, like "2002-02-28 23:00:12". UsertimeStamp call unixTimeStamp to interpret $ STR, and the $ FMT preset is Y-m-D h: i: s. Unixdate ($ STR) interpreted the date string $ STR and converted into UNIX MKTIME format (from 1970.01.01 00:00:00 to the current number of seconds). The preset date is incorporated in Y-m-D h: i: s format. For Sybase and Microsoft SQL Server, M D Y is also acceptable (the monthly representation of three characters is controlled by a domain array, this part may need to be in place). Since the 1.91 version, this function exists in two places in AdoCordset and Adoconnection. UnixTimeStamp ($ STR) interpreted the Time String $ Str and converted into UNIX MKTIME format (from 1970.01.01 00:00:00 to the current number of seconds). The preset date is incorporated in Y-m-D h: i: s format. For Sybase and Microsoft SQL Server, M D Y is also acceptable (the monthly representation of three characters is controlled by a domain array, this part may need to be in place). Since the 1.91 version, this function exists in two places in AdoCordset and Adoconnection. MoveNext () Mobile internal indicators to the next, the Fields array will be updated automatically. If you can't move, it will return the false value, and other situations will return True. Example: $ r = $ dB-> EXECUTE ($ SQL); if ($ r) While (! $ r-> eof) { ProcessArray ($ RS-> Fields); $ r-> movelnext (); } Move ($ TO) Mobile internal indicator to the specified column ($ to). The number of columns is zero, for example, 0 is the first column. The Fields array will be automatically updated. The AdoDB will automatically simulate the scroll for the database that does not support internal rollover. Part of the database is not supported backwards. For most of the database, if the location of $ to is after EOF, $ To will be moved to the last pen of the information set. Some unnamed databases may have no action when using ODBC. Note: This function uses absolute addressing, unlike ADOs of Microsoft. The return value is TRUE or FALSE. If it is false, this internal indicator is not moved in most actual operations, so absolutePosition () will return the indicator to the last position MoveFirst () actually call Move (0) before performing Move (). Note that there are some databases that do not support this function. MoveLast () is actually called Move (RecordCount () - 1). Note that there are some databases that do not support this function. Getrowassoc ($ TouPper = TRUE) This function does not sustain content to maintain the contents of the connected array in an ideal way (once a record, you will re-execute once). Use $ adoDb_fetch_mode to share variables to replace it. Back to a closed array containing current records, the index value of the array is the column name. The field name is all capitalized for access. To get the next record, you have to call MoveNext (). Example: array ([id] => 1 [firstname] => caroline [lastname] => miranda [create) => 2001-07-05) Note: Don't use Getrowassoc () and $ ADODB_FETCH_MODE = AdoDB_Fetch_assoc. Because they have the same function, they will interact with each other. AbsolutePage ($ PAGE = -1) Retrieves the current page number, you need to call PageExecute () / cachepageexecute (). Example 8. AtfirstPage ($ status = '') If on the first page, return True (1 basic form ", you need to call pageEexecute () / cachepageexecute (). Example 8. AtlastPage ($ status = '') If on the last page, return True (1 basic form ", you need to call pageexecute () / cachepageexecute (). Example 8. Fields ($ colname) is not encouraged, please replace with $ adoDb_fetch_mode. When using the native function library, some of the database functions back to the subkey and the index dual array (such as MySQL). Getrowassoc () does not return the array elements combined with the name and index. This function returns the column value of the column of $ colname, in the current record. The column name is case sensitive. Fetchrow () returns the array of current recordings, if it is the end (EOF), return FALSE. Note: Do not mix Fetchrow and MoveNext (). Usage: $ r = $ dB-> EXECUTE ($ SQL); if ($ r) While ($ arr = $ r-> fetchrow ()) { # Process $ ARR } Fetchinto (& $ array) Sets $ array to the current record. If you are in the tail (EOF), return the Pear_ERROR object. If successful, return 1 (DB_OK constant). If the PEAR is not defined, it will return false when EOF. Fetchrow () is easy to use, please take the previous example. Fetchfield ($ column_number) comes back to an item that contains the name, category, and maximum length of the fingered field. If the maximum length cannot be explicitly decided, it will be transferred to -1. The line number is the starting point of the 0 basal, please refer to Example 2. Fieldcount () Recycling the number of fields. Recordcount () Retrieve the number of records in the data set. If you cannot get the correct number from the database driver API, AdoDB will store all records, stored in the memory, and so on, return to the number of records. This memory can be canceled by setting the whole country variable $ adoDB_CounTeRECS = FALSE (based on the reason for performing performance). When canceled, for some database, RecordCount () will return -1. Relevant support conditions, please take a detailed description of the previous database support form. RowCount and RecordCount are synonymous functions. PO_RECORDCOUNT ($ TABLE, $ Where) Retrieve the number of records in the data set. If the database does not support, the value will be returned to the value of the $ TABLE trench with $ where as the condition of $ Where. $ NumRows = $ r-> PO_RECORDCOUNT ("Articles_TABLE", "GROUP = $ group"); will return the repository to execute select count (*) from articles_table where group = $ group results. Fetchobject ($ TouPper = true) Recycling the current record as an object. If $ TouPper is True, the item field name will be set to uppercase. Note: Newfall FetchNextObject () is a way to obtain record objects, please see later. FetchNextObject ($ TouPper = true) acquires the current record into one item and automatically moves to the next record. If you are at the end, return false. If $ TouPper is True, the item field name will be set to uppercase. $ r = $ db-> execute ('select firstname, lastname from table "; if ($ r) { While ($ o = $ r-> fetchnextObject ()) { Print "$ O-> Firstname, $ O-> Lastname } } When using fetchnextObject (), it will affect the performance. If the performance is important, you should use the Fields [] array to access. Currentrow () Clears the record number of the current data set, 0 is the first. AbsolutePosition () and currentrow are the same function, which is to be in order to compatibility with ADO. Metatype ($ nativedbtype [, $ field_max_length], [$ fieldobj]) Sets the native type of Native $ nativeDbtype in the database is the general data type, and its maximum length. Please note that if the length is unknown, it can be set to -1. The field item can be incorporated with $ fieldobj. This is useful for database libraries such as a type of mysql with more attributes. Use the field blobsize and compare $ field_max_length to decide if the current field is blob. Back to the value: C: Character field, you should use the tag to get the value. X: Text, long text field, use the Function RS2HTML ($ TABLORDSET, [$ TABLEHEADER_ATTRIBUTES], [$ col_titles]) This is a separate function (RS2Heml = RecordSet to HTML), equivalent to the ODBC_RESULT_ALL function in PHP. This function will output a whole adorecordset, $ adorecordset, like an HTML form. $ TABLEHEADER_ATTRIBUTES allows you to control the attributes in the form such as cellpadding, cellspacing, and border et al. Finally, you can replace the database field name through the $ col_titles array, use your own field to look up. This is a mechanism for designing quickly amplifies, not a good table record browser. To use this function, you must introduce tohtml.inc.php. RS2HTML sample: INCLUDE ('tohtml.inc.php'); # loading code Common to adoDB Include ('adoDb.inc.php'); # loading code Common to adoDB $ conn = & adonewconnection ('mysql'); # CREATE A Connection $ conn-> PConnect ('localhost', 'userid', ',' agora '); # connect to mysql, agora db $ SQL = 'Select Customername, Customerid from Customers'; $ r = $ conn-> execute ($ sql); RS2HTML ($ RS, 'Border = 2 Cellpadding = 3', Array ('Customer Name', 'Customer ID'));?> Thank you ----------------- PHP Adodb 1.99 version manual Chinese translation Tripc
";