fixed typo in security checks for prescription access
[openemr.git] / library / adodb / docs-adodb.htm
blobb2f2d69bfbf5a36f237a1a1d0ccfb8a2268eb696
1 <html>
2 <head>
3 <title>ADODB Manual</title>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5 <XSTYLE
6 body,td {font-family:Arial,Helvetica,sans-serif;font-size:11pt}
7 pre {font-size:9pt}
8 .toplink {font-size:8pt}
9 />
10 </head>
11 <body bgcolor="#FFFFFF">
13 <h2>ADOdb Library for PHP</h2>
14 <p>V4.20 22 Feb 2004 (c) 2000-2004 John Lim (jlim#natsoft.com)</p>
15 <p><font size="1">This software is dual licensed using BSD-Style and LGPL. This
16 means you can use it in compiled proprietary and commercial products.</font></p>
17 <p>Useful ADOdb links: <a href=http://php.weblogs.com/adodb>Download</a> &nbsp; <a href=http://php.weblogs.com/adodb_manual>Other Docs</a>
19 <p><a href="#intro"><b>Introduction</b></a><b><br>
20 <a href="#features">Unique Features</a><br>
21 <a href="#users">How People are using ADOdb</a><br>
22 <a href="#bugs">Feature Requests and Bug Reports</a><br>
23 </b><b><a href="#install">Installation</a><br>
24 <a href="#mininstall">Minimum Install</a><br>
25 <a href="#coding">Initializing Code and Connection Examples</a><br>
26 <font size="2"><a href=#adonewconnection>ADONewConnection</a></font>
27 <font size="2"><a href=#adonewconnection>NewADOConnection</a></font><br>
28 <a href="#speed">High Speed ADOdb - tuning tips</a></b><br>
29 <b><a href="#hack">Hacking and Modifying ADOdb Safely</a><br>
30 <a href="#php5">PHP5 Features</a></b><br>
31 <font size="2"><a href=#php5iterators>foreach iterators</a> <a href=#php5exceptions>exceptions</a></font><br>
32 <b> <a href="#drivers">Supported Databases</a></b><br>
33 <b> <a href="#quickstart">Tutorials</a></b><br>
34 <a href="#ex1">Example 1: Select</a><br>
35 <a href="#ex2">Example 2: Advanced Select</a><br>
36 <a href="#ex3">Example 3: Insert</a><br>
37 <a href="#ex4">Example 4: Debugging</a> &nbsp;<a href="#exrs2html">rs2html
38 example</a><br>
39 <a href="#ex5">Example 5: MySQL and Menus</a><br>
40 <a href="#ex6">Example 6: Connecting to Multiple Databases at once</a> <br>
41 <a href="#ex7">Example 7: Generating Update and Insert SQL</a> <br>
42 <a href="#ex8">Example 8: Implementing Scrolling with Next and Previous</a><br>
43 <a href="#ex9">Example 9: Exporting in CSV or Tab-Delimited Format</a> <br>
44 <a href="#ex10">Example 10: Custom filters</a><br>
45 <a href="#ex11">Example 11: Smart Transactions</a><br>
46 <br>
47 <b> <a href="#errorhandling">Using Custom Error Handlers and PEAR_Error</a><br>
48 <a href="#DSN">Data Source Names</a><br>
49 <a href="#caching">Caching</a><br>
50 <a href="#pivot">Pivot Tables</a></b>
51 <p><a href="#ref"><b>REFERENCE</b></a>
52 <p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> <a href=#adodb_ansi_padding_off>$ADODB_ANSI_PADDING_OFF</a>
53 <a href="#adodb_cache_dir">$ADODB_CACHE_DIR</a> </font><font size="2"><a href=#adodb_fetch_mode>$ADODB_FETCH_MODE</a>
54 <a href=#adodb_lang>$ADODB_LANG</a><br>
55 Constants: </font><font size="2"><a href=#adodb_assoc_case>ADODB_ASSOC_CASE</a>
56 </font><br>
57 <a href="#ADOConnection"><b> ADOConnection</b></a><br>
58 <font size="2">Connections: <a href="#connect">Connect</a> <a href="#pconnect">PConnect</a>
59 <a href="#nconnect">NConnect</a> <br>
60 Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute"><i>CacheExecute</i></a>
61 <a href="#SelectLimit">SelectLimit</a> <a href="#cacheSelectLimit"><i>CacheSelectLimit</i></a>
62 <a href="#param">Param</a> <a href="#prepare">Prepare</a> <a href=#preparesp>PrepareSP</a>
63 <a href="#inparameter">InParameter</a> <a href="#outparameter">OutParameter</a>
64 <br>
65 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#getone">GetOne</a>
66 <a href="#cachegetone"><i>CacheGetOne</i></a> <a href="#getrow">GetRow</a> <a href="#cachegetrow"><i>CacheGetRow</i></a>
67 <a href="#getall">GetAll</a> <a href="#cachegetall"><i>CacheGetAll</i></a> <a href="#getcol">GetCol</a>
68 <a href="#cachegetcol"><i>CacheGetCol</i></a> <a href="#getassoc1">GetAssoc</a> <a href="#cachegetassoc"><i>CacheGetAssoc</i></a> <a href="#replace">Replace</a>
69 <br>
70 &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#executecursor">ExecuteCursor</a>
71 (oci8 only)<br>
72 Generates SQL strings: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a>
73 <a href="#concat">Concat</a> <a href="#ifnull">IfNull</a> <a href="#length">length</a> <a href="#random">random</a> <a href="#substr">substr</a>
74 <a href="#qstr">qstr</a> <a href="#param">Param</a>
75 <a href="#prepare"></a><a href="#OffsetDate">OffsetDate</a> <a href="#SQLDate">SQLDate</a>
76 <a href="#dbdate">DBDate</a> <a href="#dbtimestamp"></a> <a href="#dbtimestamp">DBTimeStamp</a>
77 <br>
78 Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a>
79 <a href="#updateblobfile">UpdateBlobFile</a> <a href="#blobencode">BlobEncode</a>
80 <a href="#blobdecode">BlobDecode</a><br>
81 Paging/Scrolling: <a href="#pageexecute">PageExecute</a> <a href="#cachepageexecute">CachePageExecute</a><br>
82 Cleanup: <a href="#cacheflush">CacheFlush</a> <a href="#Close">Close</a><br>
83 Transactions: <a href="#starttrans">StartTrans</a> <a href="#completetrans">CompleteTrans</a>
84 <a href="#failtrans">FailTrans</a> <a href="#hasfailedtrans">HasFailedTrans</a>
85 <a href="#begintrans">BeginTrans</a> <a href="#committrans">CommitTrans</a>
86 <a href="#rollbacktrans">RollbackTrans</a> <br>
87 Fetching Data: </font> <font size="2"><a href="#setfetchmode">SetFetchMode</a><br>
88 Strings: <a href="#concat">concat</a> <a href="#length">length</a> <a href="#qstr">qstr</a> <a href="#quote">quote</a> <a href="#substr">substr</a><br>
89 Dates: <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> <a href="#unixdate">UnixDate</a>
90 <a href="#unixtimestamp">UnixTimeStamp</a> <a href="#OffsetDate">OffsetDate</a>
91 <a href="#SQLDate">SQLDate</a> <br>
92 Row Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a> <a href=#rowlock>RowLock</a>
93 <a href="#genid">GenID</a> <a href=#createseq>CreateSequence</a> <a href=#dropseq>DropSequence</a>
94 <br>
95 Error Handling: <a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a>
96 <a href="#metaerror">MetaError</a> <a href="#metaerrormsg">MetaErrorMsg</a><br>
97 Data Dictionary (metadata): <a href="#metadatabases">MetaDatabases</a> <a href="#metatables">MetaTables</a>
98 <a href="#metacolumns">MetaColumns</a> <a href="#metacolumnames">MetaColumnNames</a>
99 <a href="#metaprimarykeys">MetaPrimaryKeys</a> <a href="#metaforeignkeys">MetaForeignKeys</a>
100 <a href="#serverinfo">ServerInfo</a> <br>
101 Statistics and Query-Rewriting: <a href="#logsql">LogSQL</a> <a href="#fnexecute">fnExecute
102 and fnCacheExecute</a><br>
103 </font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a>
104 <a href="#parameter">Parameter</a></font>
105 <a href="#adorecordSet"><b><br>
106 ADORecordSet</b></a><br>
107 <font size="2">
108 Returns one field: <a href="#fields">Fields</a><br>
109 Returns one row:<a href="#fetchrow">FetchRow</a> <a href="#fetchinto">FetchInto</a>
110 <a href="#fetchobject">FetchObject</a> <a href="#fetchnextobject">FetchNextObject</a>
111 <a href="#fetchobj">FetchObj</a> <a href="#fetchnextobj">FetchNextObj</a>
112 <a href="#getrowassoc">GetRowAssoc</a> <br>
113 Returns all rows:<a href="#getarray">GetArray</a> <a href="#getrows">GetRows</a>
114 <a href="#getassoc">GetAssoc</a><br>
115 Scrolling:<a href="#move">Move</a> <a href="#movenext">MoveNext</a> <a href="#movefirst">MoveFirst</a>
116 <a href="#movelast">MoveLast</a> <a href="#abspos">AbsolutePosition</a> <a href="#currentrow">CurrentRow</a>
117 <a href="#atfirstpage">AtFirstPage</a> <a href="#atlastpage">AtLastPage</a>
118 <a href="#absolutepage">AbsolutePage</a> </font> <font size="2"><br>
119 Menu generation:<a href="#getmenu">GetMenu</a> <a href="#getmenu2">GetMenu2</a><br>
120 Dates:<a href="#userdate">UserDate</a> <a href="#usertimestamp">UserTimeStamp</a>
121 <a href="#unixdate">UnixDate</a> <a href="#unixtimestamp">UnixTimeStamp<br>
122 </a>Recordset Info:<a href="#recordcount">RecordCount</a> <a href="#po_recordcount">PO_RecordSet</a>
123 <a href="#nextrecordset">NextRecordSet</a><br>
124 Field Info:<a href="#fieldcount">FieldCount</a> <a href="#fetchfield">FetchField</a>
125 <a href="#metatype">MetaType</a><br>
126 Cleanup: <a href="#rsclose">Close</a></font> <font size="2"></font>
127 <p><font size="2"><a href="#rs2html"><b>rs2html</b></a>&nbsp; <a href="#exrs2html">example</a></font><br>
128 <a href="#adodiff">Differences between ADOdb and ADO</a><br>
129 <a href="#driverguide"><b>Database Driver Guide<br>
130 </b></a><b><a href="#changes">Change Log</a></b><br>
131 </p>
132 <h2>Introduction<a name="intro"></a></h2>
133 <p>PHP's database access functions are not standardised. This creates a need for
134 a database class library to hide the differences between the different database
135 API's (encapsulate the differences) so we can easily switch databases. PHP 4.0.5 or later
136 is now required (because we use array-based str_replace).</p>
137 <p>We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix,
138 PostgreSQL, FrontBase, SQLite, Interbase (Firebird and Borland variants), Foxpro, Access, ADO, DB2, SAP DB and ODBC.
139 We have had successful reports of connecting to Progress and CacheLite via ODBC. We hope more people
140 will contribute drivers to support other databases.</p>
141 <p>PHP4 supports session variables. You can store your session information using
142 ADOdb for true portability and scalability. See adodb-session.php for more information.</p>
143 <p>Also read <a href="http://php.weblogs.com/portable_sql">http://php.weblogs.com/portable_sql</a>
144 (also available as tips_portable_sql.htm in the release) for tips on writing
145 portable SQL.</p>
146 <h2>Unique Features of ADOdb<a name="features"></a></h2>
147 <ul>
148 <li><b>Easy for Windows programmers</b> to adapt to because many of the conventions
149 are similar to Microsoft's ADO.</li>
150 <li>Unlike other PHP database classes which focus only on select statements,
151 <b>we provide support code to handle inserts and updates which can be adapted
152 to multiple databases quickly.</b> Methods are provided for date handling,
153 string concatenation and string quoting characters for differing databases.</li>
154 <li>A<b> metatype system </b>is built in so that we can figure out that types
155 such as CHAR, TEXT and STRING are equivalent in different databases.</li>
156 <li><b>Easy to port</b> because all the database dependant code are stored in
157 stub functions. You do not need to port the core logic of the classes.</li>
158 <li><b>Portable table and index creation</b> with the <a href=docs-datadict.htm>datadict</a> classes.
159 <li><b>Database performance monitoring and SQL tuning</b> with the <a href=docs-perf.htm>performance monitoring</a> classes.
160 <li><b>Database-backed sessions</b> with the <a href=docs-session.htm>session management</a> classes. Supports session expiry notification.
161 </ul>
162 <h2>How People are using ADOdb<a name="users"></a></h2>
163 Here are some examples of how people are using ADOdb (for a much longer list,
164 visit <a href="http://php.weblogs.com/adodb-cool-applications">http://php.weblogs.com/adodb-cool-applications</a>):
165 <ul>
166 <li><a href="http://phplens.com/">PhpLens</a> is a commercial data grid component that allows both cool Web designers and serious unshaved programmers to develop and maintain databases on the Web easily. Developed by the author of ADOdb.<p>
168 <li><a href="http://www.interakt.ro/phakt/">PHAkt: PHP Extension for DreamWeaver Ultradev</a> allows you to script PHP in the popular Web page editor. Database handling provided by ADOdb.<p>
170 <li><a href="http://www.andrew.cmu.edu/~rdanyliw/snort/snortacid.html">Analysis Console for Intrusion Databases</a> (ACID): PHP-based analysis engine to search and process a database of security incidents generated by security-related software such as IDSes and firewalls (e.g. Snort, ipchains). By Roman Danyliw.<p>
172 <li><a href="http://www.postnuke.com/">PostNuke</a> is a very popular free content management
173 system and weblog system. It offers full CSS support, HTML 4.01 transitional compliance throughout, an advanced blocks system, and is fully multi-lingual enabled. <p>
175 <li><a href=http://www.auto-net.no/easypublish.php?page=index&lang_id=2>EasyPublish CMS</a> is another free content management system for managing information and integrated modules on your internet, intranet- and extranet-sites. From Norway.<p>
177 <li><a href="http://nola.noguska.com/">NOLA</a> is a full featured accounting, inventory, and job tracking application. It is licensed under the GPL, and developed by Noguska.
178 </ul><p>
180 <h2>Feature Requests and Bug Reports<a name="bugs"></a></h2>
181 <p>Feature requests and bug reports can be emailed to <a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a>
182 or posted to the ADOdb Help forums at <a href="http://phplens.com/lens/lensforum/topics.php?id=4">http://phplens.com/lens/lensforum/topics.php?id=4</a>.</p>
183 <h2>Installation Guide<a name="install"></a></h2>
184 <p>Make sure you are running PHP 4.0.4 or later.
185 Unpack all the files into a directory accessible by your webserver.</p>
186 <p>To test, try modifying some of the tutorial examples. Make sure you customize
187 the connection settings correctly. You can debug using <i>$db->debug = true</i> as shown below:</p>
188 <pre>&lt;?php
189 include('adodb/adodb.inc.php');
190 $db = <a href="#adonewconnection">ADONewConnection</a>($dbdriver); # eg 'mysql' or 'postgres'
191 $db->debug = true;
192 $db-><a href="#connect">Connect</a>($server, $user, $password, $database);
193 $rs = $db-><a href="#execute">Execute</a>('select * from some_small_table');
194 print &quot;&lt;pre&gt;&quot;;
195 print_r($rs-><a href="#getrows">GetRows</a>());
196 print &quot;&lt;/pre&gt;&quot;;
197 ?&gt;</pre>
199 <h3>Minimum Install<a name=mininstall></a></h3>
200 <p>For developers who want to release a minimal install of ADOdb, you will need:
201 <ul>
202 <li>adodb.inc.php
203 <li>adodb-lib.inc.php
204 <li>adodb-time.inc.php
205 <li>adodb-csvlib.inc.php (if you use cached recordsets - CacheExecute(), etc)
206 <li>adodb-error.inc.php and lang/adodb-$lang.inc.php (if you use MetaError())
207 <li>drivers/adodb-$database.inc.php
208 <li>license.txt (for legal reasons)
209 </ul>
211 <h3>Code Initialization Examples<a name="coding"></a></h3>
212 <p>When running ADOdb, at least two files are loaded. First is adodb/adodb.inc.php,
213 which contains all functions used by all database classes. The code specific
214 to a particular database is in the adodb/driver/adodb-????.inc.php file.</p>
215 <a name="adonewconnection">
216 <p>For example, to connect to a mysql database:</p>
217 <pre>
218 include('/path/to/set/here/adodb.inc.php');
219 $conn = &amp;ADONewConnection('mysql');
220 </pre>
221 <p>Whenever you need to connect to a database, you create a Connection object
222 using the <b>ADONewConnection</b></a>($driver) function.
223 <b>NewADOConnection</b>($driver) is an alternative name for the same function.</p>
225 <p>At this point, you are not connected to the database. You will first need to decide
226 whether to use <i>persistent</i> or <i>non-persistent</i> connections. The advantage of <i>persistent</i>
227 connections is that they are faster, as the database connection is never closed (even
228 when you call Close()). <i>Non-persistent </i>connections take up much fewer resources though,
229 reducing the risk of your database and your web-server becoming overloaded.
230 <p>For persistent connections,
231 use $conn-&gt;<a href="reference.functions.pconnect.html">PConnect()</a>,
232 or $conn-&gt;<a href="reference.functions.connect.html">Connect()</a> for non-persistent connections.
233 Some database drivers also support <a href="reference.functions.nconnect.html">NConnect()</a>, which forces
234 the creation of a new connection.
235 <a name=connection_gotcha></a>
236 <p><i>Connection Gotcha</i>: If you create two connections, but both use the same userid and password,
237 PHP will share the same connection. This can cause problems if the connections are meant to
238 different databases. The solution is to always use different userid's for different databases,
239 or use NConnect().
241 <h3>Examples of Connecting to Databases</h3>
242 <h4>MySQL and Most Other Database Drivers</h4>
243 <p>MySQL connections are very straightforward, and the parameters are identical
244 to mysql_connect:</p>
245 <pre>
246 $conn = &amp;ADONewConnection('mysql');
247 $conn-&gt;PConnect('localhost','userid','password','database');
248 </pre>
249 <p> Most other database drivers use a similar convention: Connect($server, $user, $password, $database). Exceptions are listed below.
250 <h4>PostgreSQL</h4>
251 <p>PostgreSQL accepts connections using: </p>
252 <p>a. the standard connection string:</p>
253 <pre>
254 $conn = &amp;ADONewConnection('postgres7');
255 $conn-&gt;PConnect('host=localhost port=5432 dbname=mary');</pre>
256 <p> b. the classical 4 parameters:</p>
257 <pre>
258 $conn-&gt;PConnect('localhost','userid','password','database');
259 </pre>
260 <h4>Interbase/Firebird</h4>
261 You define the database in the $host parameter:
262 <pre>
263 $conn = &ADONewConnection('ibase');
264 $conn->PConnect('localhost:c:\ibase\employee.gdb','sysdba','masterkey');
265 </pre>
266 <h4>SQLite</h4>
267 Sqlite will create database if it does not exist.
268 <pre>
269 $conn = &ADONewConnection('sqlite');
270 $conn->PConnect('c:\path\to\sqlite.db'); # sqlite will create if does not exist
271 </pre>
272 <h4>Oracle</h4>
273 <p>With Oracle, you can connect in multiple ways.</p>
274 <p>a. PHP and Oracle reside on the same machine, use default SID.</p>
275 <pre> $conn-&gt;Connect(false, 'scott', 'tiger');</pre>
276 <p>b. TNS Name defined, eg. 'myTNS'</p>
277 <pre> $conn-&gt;PConnect(false, 'scott', 'tiger', 'myTNS');
278 </pre>
279 <p>or</p>
280 <pre> $conn-&gt;PConnect('myTNS', 'scott', 'tiger');</pre>
281 <p>c. Host Address and SID</p>
282 <pre> $conn-&gt;Connect('192.168.0.1', 'scott', 'tiger', 'SID');</pre>
283 <p>d. Host Address and Service Name</p>
284 <pre> $conn-&gt;Connect('192.168.0.1', 'scott', 'tiger', 'servicename');</pre>
285 <a name=dsnless></a>
286 <h4>DSN-less ODBC (access and mssql examples)</h4>
287 <p>ODBC DSN's can be created in the ODBC control panel, or you can use a DSN-less
288 connection.To use DSN-less connections with ODBC you need PHP 4.3 or later.
289 </p>
290 <p>For Microsoft Access:</a></p>
291 <pre>
292 $db =& ADONewConnection('access');
293 $dsn = <strong>"Driver=&#123;Microsoft Access Driver (*.mdb)&#125;;Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;";</strong>
294 $db->Connect($dsn);
295 </pre>
296 For Microsoft SQL Server:
297 <pre>
298 $db =& ADONewConnection('odbc_mssql');
299 $dsn = <strong>"Driver=&#123;SQL Server&#125;;Server=localhost;Database=northwind;"</strong>;
300 $db->Connect($dsn,'userid','password');
301 </pre>
302 <b>DSN-less Connections with ADO</b><br>
303 If you are using versions of PHP earlier than PHP 4.3.0, DSN-less connections
304 only work with Microsoft's ADO, which is Microsoft's COM based API. An example
305 using the ADOdb library and Microsoft's ADO:
306 <pre>
307 &lt;?php
308 include('adodb.inc.php');
309 $db = &ADONewConnection("ado_mssql");
310 print "&lt;h1>Connecting DSN-less $db->databaseType...&lt;/h1>";
312 <b>$myDSN="PROVIDER=MSDASQL;DRIVER=&#123;SQL Server&#125;;"
313 . "SERVER=flipper;DATABASE=ai;UID=sa;PWD=;" ;</b>
314 $db->Connect($myDSN);
316 $rs = $db->Execute("select * from table");
317 $arr = $rs->GetArray();
318 print_r($arr);
320 </pre><a name=speed></a>
321 <h2>High Speed ADOdb - tuning tips</h2>
322 <p>ADOdb is a big class library, yet it <a href=http://phplens.com/lens/adodb/>consistently beats</a> all other PHP class
323 libraries in performance. This is because it is designed in a layered fashion,
324 like an onion, with the fastest functions in the innermost layer. Stick to the
325 following functions for best performance:</p>
326 <table width="40%" border="1" align="center">
327 <tr>
328 <td><div align="center"><b>Innermost Layer</b></div></td>
329 </tr>
330 <tr>
331 <td><p align="center">Connect, PConnect, NConnect<br>
332 Execute, CacheExecute<br>
333 SelectLimit, SelectLimit<br>
334 MoveNext, Close <br>
335 qstr, Affected_Rows, Insert_ID</p></td>
336 </tr>
337 </table>
338 <p>The fastest way to access the fields is by accessing the array $recordset->fields
339 directly. Also set the global variables <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>
340 = ADODB_FETCH_NUM, and (for oci8, ibase/firebird and odbc) <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> = false
341 before you connect to your database. At the time of writing (Dec 2003).</p>
342 <p>Consider using bind parameters if your database supports it, as it improves
343 query plan reuse. Use ADOdb's performance tuning system to identify bottlenecks
344 quickly. At the time of writing (Dec 2003), this means oci8 and odbc drivers.</p>
345 <p>Lastly make sure you have a PHP accelerator cache installed such as APC, Turck
346 MMCache, Zend Accelerator or ionCube.</p>
347 <p>Informix tips: Disable scrollable cursors with $db->cursorType = 0.
348 <p><a name=hack></a> </p>
349 <h2>Hacking ADOdb Safely</h2>
350 <p>You might want to modify ADOdb for your own purposes. Luckily you can
351 still maintain backward compatibility by sub-classing ADOdb and using the $ADODB_NEWCONNECTION
352 variable. $ADODB_NEWCONNECTION allows you to override the behaviour of ADONewConnection().
353 ADOConnection() checks for this variable and will call
354 the function-name stored in this variable if it is defined.
355 <p>In the following example, new functionality for the connection object
356 is placed in the <i>hack_mysql</i> and <i>hack_postgres7</i> classes. The recordset class naming convention
357 can be controlled using $rsPrefix. Here we set it to 'hack_rs_', which will make ADOdb use
358 <i>hack_rs_mysql</i> and <i>hack_rs_postgres7</i> as the recordset classes.
359 If you want to use the default ADOdb drivers return false.
361 <pre>
362 class hack_mysql extends adodb_mysql {
363 var $rsPrefix = 'hack_rs_';
364 /* Your mods here */
367 class hack_rs_mysql extends ADORecordSet_mysql {
368 /* Your mods here */
371 class hack_postgres7 extends adodb_postgres7 {
372 var $rsPrefix = 'hack_rs_';
373 /* Your mods here */
376 class hack_rs_postgres7 extends ADORecordSet_postgres7 {
377 /* Your mods here */
380 $ADODB_NEWCONNECTION = 'hack_factory';
382 function& hack_factory($driver)
384 if ($driver !== 'mysql' && $driver !== 'postgres7') return false;
386 $driver = 'hack_'.$driver;
387 $obj = new $driver();
388 return $obj;
391 include_once('adodb.inc.php');
393 </pre>
394 <p>Don't forget to call the constructor of the parent class.
395 <a name="php5">
396 <h2>PHP5 Features</h2>
397 ADOdb 4.02 or later will transparently determine which version of PHP you are using.
398 If PHP5 is detected, the following features become available:
399 <ul>
400 <a name="php5iterators">
401 <li><b>Foreach iterators</b>: This is a very natural way of going through a recordset:
402 <pre>
403 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
404 $rs = $db->Execute($sql);
405 foreach($rs as $k => $row) {
406 echo "r1=".$row[0]." r2=".$row[1]."&lt;br>";
408 </pre>
410 <a name="php5exceptions">
411 <li><b>Exceptions</b>: Just include <i>adodb-exceptions.inc.php</i> and you can now
412 catch exceptions on errors as they occur.
413 <pre>
414 <b>include("../adodb-exceptions.inc.php");</b>
415 include("../adodb.inc.php");
416 try {
417 $db = NewADOConnection("oci8");
418 $db->Connect('','scott','bad-password');
419 } catch (exception $e) {
420 var_dump($e);
422 </pre>
423 </ul>
424 <h3><a name="drivers"></a>Databases Supported</h3>
425 <table width="100%" border="1">
426 <tr valign="top">
427 <td><b>Name</b></td>
428 <td><b>Tested</b></td>
429 <td><b>Database</b></td>
430 <td><b><font size="2">RecordCount() usable</font></b></td>
431 <td><b>Prerequisites</b></td>
432 <td><b>Operating Systems</b></td>
433 </tr>
434 <tr valign="top">
435 <td><b><font size="2">access</font></b></td>
436 <td><font size="2">B</font></td>
437 <td><font size="2">Microsoft Access/Jet. You need to create an ODBC DSN.</font></td>
438 <td><font size="2">Y/N</font></td>
439 <td><font size="2">ODBC </font></td>
440 <td><font size="2">Windows only</font></td>
441 </tr>
442 <tr valign="top">
443 <td><b><font size="2">ado</font></b></td>
444 <td><font size="2">B</font></td>
445 <td><p><font size="2">Generic ADO, not tuned for specific databases. Allows
446 DSN-less connections. For best performance, use an OLEDB provider. This
447 is the base class for all ado drivers.</font></p>
448 <p><font size="2">You can set $db-&gt;codePage before connecting.</font></p></td>
449 <td><font size="2">? depends on database</font></td>
450 <td><font size="2">ADO or OLEDB provider</font></td>
451 <td><font size="2">Windows only</font></td>
452 </tr>
453 <tr valign="top">
454 <td><b><font size="2">ado_access</font></b></td>
455 <td><font size="2">B</font></td>
456 <td><font size="2">Microsoft Access/Jet using ADO. Allows DSN-less connections.
457 For best performance, use an OLEDB provider.</font></td>
458 <td><font size="2">Y/N</font></td>
459 <td><font size="2">ADO or OLEDB provider</font></td>
460 <td><font size="2">Windows only</font></td>
461 </tr>
462 <tr valign="top">
463 <td><b><font size="2">ado_mssql</font></b></td>
464 <td><font size="2">B</font></td>
465 <td><font size="2">Microsoft SQL Server using ADO. Allows DSN-less connections.
466 For best performance, use an OLEDB provider.</font></td>
467 <td><font size="2">Y/N</font></td>
468 <td><font size="2">ADO or OLEDB provider</font></td>
469 <td><font size="2">Windows only</font></td>
470 </tr>
471 <tr valign="top">
472 <td height="54"><b><font size="2">db2</font></b></td>
473 <td height="54"><font size="2">A</font></td>
474 <td height="54"><font size="2">DB2. Should work reliably as based on ODBC
475 driver.</font></td>
476 <td height="54"><font size="2">Y/N</font></td>
477 <td height="54"><font size="2">DB2 CLI/ODBC interface</font></td>
478 <td height="54"> <p><font size="2">Unix and Windows. <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/6283/fid/14">Unix
479 install hints</a>. I have had reports that the $host and $database params have to be reversed in Connect() when using the CLI interface.</font></p></td>
480 </tr>
481 <tr valign="top">
482 <td><b><font size="2">vfp</font></b></td>
483 <td><font size="2">A</font></td>
484 <td><font size="2">Microsoft Visual FoxPro. You need to create an ODBC DSN.</font></td>
485 <td><font size="2">Y/N</font></td>
486 <td><font size="2">ODBC</font></td>
487 <td><font size="2">Windows only</font></td>
488 </tr>
489 <tr valign="top">
490 <td><b><font size="2">fbsql</font></b></td>
491 <td><font size="2">C</font></td>
492 <td><font size="2">FrontBase. </font></td>
493 <td><font size="2">Y</font></td>
494 <td><font size="2">?</font></td>
495 <td> <p><font size="2">Unix and Windows</font></p></td>
496 </tr>
497 <tr valign="top">
498 <td><b><font size="2">ibase</font></b></td>
499 <td><font size="2">B</font></td>
500 <td><font size="2">Interbase 6 or earlier. Some users report you might need
501 to use this<br>
502 $db->PConnect('localhost:c:/ibase/employee.gdb', "sysdba", "masterkey")
503 to connect. Lacks Affected_Rows currently.<br>
504 <br>
505 You can set $db->dialect, $db-&gt;buffers and $db->charSet before connecting.</font></td>
506 <td><font size="2">Y/N</font></td>
507 <td><font size="2">Interbase client</font></td>
508 <td><font size="2">Unix and Windows</font></td>
509 </tr>
510 <tr valign="top">
511 <td><b><i><font size="2">firebird</font></i></b></td>
512 <td><font size="2">C</font></td>
513 <td><font size="2">Firebird version of interbase.</font></td>
514 <td><font size="2">Y/N</font></td>
515 <td><font size="2">Interbase client</font></td>
516 <td><font size="2">Unix and Windows</font></td>
517 </tr>
518 <tr valign="top">
519 <td><b><i><font size="2">borland_ibase</font></i></b></td>
520 <td><font size="2">C</font></td>
521 <td><font size="2">Borland version of Interbase 6.5 or later. Very sad that
522 the forks differ.</font></td>
523 <td><font size="2">Y/N</font></td>
524 <td><font size="2">Interbase client</font></td>
525 <td><font size="2">Unix and Windows</font></td>
526 </tr>
527 <tr valign="top">
528 <td><b><font size="2">informix72</font></b></td>
529 <td><font size="2">C</font></td>
530 <td><font size="2"> Informix databases before Informix 7.3 that do no support
531 SELECT FIRST.</font></td>
532 <td><font size="2">Y/N</font></td>
533 <td><font size="2">Informix client</font></td>
534 <td><font size="2">Unix and Windows</font></td>
535 </tr>
536 <tr valign="top">
537 <td><b><font size="2">informix</font></b></td>
538 <td><font size="2">C</font></td>
539 <td><font size="2">Generic informix driver.</font></td>
540 <td><font size="2">Y/N</font></td>
541 <td><font size="2">Informix client</font></td>
542 <td><font size="2">Unix and Windows</font></td>
543 </tr>
544 <tr valign="top">
545 <td height="73"><b><font size="2">mssql</font></b></td>
546 <td height="73"><font size="2">A</font></td>
547 <td height="73"> <p><font size="2">Microsoft SQL Server 7 and later. Works
548 with Microsoft SQL Server 2000 also. Note that date formating is problematic
549 with this driver. For example, the PHP mssql extension does not return
550 the seconds for datetime!</font></p></td>
551 <td height="73"><font size="2">Y/N</font></td>
552 <td height="73"><font size="2">Mssql client</font></td>
553 <td height="73"> <p><font size="2">Unix and Windows. <br>
554 <a href="http://phpbuilder.com/columns/alberto20000919.php3">Unix install
555 howto</a> and <a href=http://linuxjournal.com/article.php?sid=6636&mode=thread&order=0>another
556 one</a>. </font></p></td>
557 </tr>
558 <tr valign="top">
559 <td height="73"><b><font size="2">mssqlpo</font></b></td>
560 <td height="73"><font size="2">A</font></td>
561 <td height="73"> <p><font size="2">Portable mssql driver. Identical to above
562 mssql driver, except that '||', the concatenation operator, is converted
563 to '+'. Useful for porting scripts from most other sql variants that use
564 ||.</font></p></td>
565 <td height="73"><font size="2">Y/N</font></td>
566 <td height="73"><font size="2">Mssql client</font></td>
567 <td height="73"> <p><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3"><br>
568 Unix install howto</a>.</font></p></td>
569 </tr>
570 <tr valign="top">
571 <td><b><font size="2">mysql</font></b></td>
572 <td><font size="2">A</font></td>
573 <td><font size="2">MySQL without transaction support. You can also set $db-&gt;clientFlags
574 before connecting.</font></td>
575 <td><font size="2">Y/N</font></td>
576 <td><font size="2">MySQL client</font></td>
577 <td><font size="2">Unix and Windows</font></td>
578 </tr>
579 <tr valign="top">
580 <td><font size="2"><b>mysqlt</b> or <b>maxsql</b></font></td>
581 <td><font size="2">A</font></td>
582 <td> <p><font size="2">MySQL with transaction support. We recommend using
583 || as the concat operator for best portability. This can be done by running
584 MySQL using: <br>
585 <i>mysqld --ansi</i> or <i>mysqld --sql-mode=PIPES_AS_CONCAT</i></font></p></td>
586 <td><font size="2">Y/N</font></td>
587 <td><font size="2">MySQL client</font></td>
588 <td><font size="2">Unix and Windows</font></td>
589 </tr>
590 <tr valign="top">
591 <td><b><font size="2">oci8</font></b></td>
592 <td><font size="2">A</font></td>
593 <td><font size="2">Oracle 8/9. Has more functionality than <i>oracle</i> driver
594 (eg. Affected_Rows). You might have to putenv('ORACLE_HOME=...') before
595 Connect/PConnect. </font> <p><font size="2"> There are 2 ways of connecting
596 - with server IP and service name: <br>
597 <i>PConnect('serverip:1521','scott','tiger','service'</i>)<br>
598 or using an entry in TNSNAMES.ORA or ONAMES or HOSTNAMES: <br>
599 <i>PConnect(false, 'scott', 'tiger', $oraname)</i>. </font>
600 <p><font size="2">Since 2.31, we support Oracle REF cursor variables directly
601 (see <a href="#executecursor">ExecuteCursor</a>).</font> </td>
602 <td><font size="2">Y/N</font></td>
603 <td><font size="2">Oracle client</font></td>
604 <td><font size="2">Unix and Windows</font></td>
605 </tr>
606 <tr valign="top">
607 <td><b><font size="2">oci805</font></b></td>
608 <td><font size="2">C</font></td>
609 <td><font size="2">Supports reduced Oracle functionality for Oracle 8.0.5.
610 SelectLimit is not as efficient as in the oci8 or oci8po drivers.</font></td>
611 <td><font size="2">Y/N</font></td>
612 <td><font size="2">Oracle client</font></td>
613 <td><font size="2">Unix and Windows</font></td>
614 </tr>
615 <tr valign="top">
616 <td><b><font size="2">oci8po</font></b></td>
617 <td><font size="2">A</font></td>
618 <td><font size="2">Oracle 8/9 portable driver. This is nearly identical with
619 the oci8 driver except (a) bind variables in Prepare() use the ? convention,
620 instead of :bindvar, (b) field names use the more common PHP convention
621 of lowercase names. </font> <p><font size="2">Use this driver if porting
622 from other databases is important. Otherwise the oci8 driver offers better
623 performance. </font> </td>
624 <td><font size="2">Y/N</font></td>
625 <td><font size="2">Oracle client</font></td>
626 <td><font size="2">Unix and Windows</font></td>
627 </tr>
628 <tr valign="top">
629 <td><b><font size="2">odbc</font></b></td>
630 <td><font size="2">A</font></td>
631 <td><font size="2">Generic ODBC, not tuned for specific databases. To connect,
632 use <br>
633 PConnect('DSN','user','pwd'). This is the base class for all odbc derived
634 drivers.</font></td>
635 <td><font size="2">? depends on database</font></td>
636 <td><font size="2">ODBC</font></td>
637 <td><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3?page=4">Unix
638 hints.</a></font></td>
639 </tr>
640 <tr valign="top">
641 <td><b><font size="2">odbc_mssql</font></b></td>
642 <td><font size="2">C</font></td>
643 <td><font size="2">Uses ODBC to connect to MSSQL</font></td>
644 <td><font size="2">Y/N</font></td>
645 <td><font size="2">ODBC</font></td>
646 <td><font size="2">Unix and Windows. </font></td>
647 </tr>
648 <tr valign="top">
649 <td><b><font size="2">odbc_oracle</font></b></td>
650 <td><font size="2">C</font></td>
651 <td><font size="2">Uses ODBC to connect to Oracle</font></td>
652 <td><font size="2">Y/N</font></td>
653 <td><font size="2">ODBC</font></td>
654 <td><font size="2">Unix and Windows. </font></td>
655 </tr>
656 <tr valign="top">
657 <td height="34"><b><font size="2">oracle</font></b></td>
658 <td height="34"><font size="2">C</font></td>
659 <td height="34"><font size="2">Implements old Oracle 7 client API. Use oci8
660 driver if possible for better performance.</font></td>
661 <td height="34"><font size="2">Y/N</font></td>
662 <td height="34"><font size="2">Oracle client</font></td>
663 <td height="34"><font size="2">Unix and Windows</font></td>
664 </tr>
665 <tr valign="top">
666 <td><b><font size="2">postgres</font></b></td>
667 <td><font size="2">A</font></td>
668 <td><font size="2">Generic PostgreSQL driver. Currently identical to postgres7
669 driver. </font></td>
670 <td><font size="2">Y</font></td>
671 <td><font size="2">PostgreSQL client</font></td>
672 <td><font size="2">Unix and Windows. </font></td>
673 </tr>
674 <tr valign="top">
675 <td><b><font size="2">postgres64</font></b></td>
676 <td><font size="2">A</font></td>
677 <td><font size="2">For PostgreSQL 6.4 and earlier which does not support LIMIT
678 internally.</font></td>
679 <td><font size="2">Y</font></td>
680 <td><font size="2">PostgreSQL client</font></td>
681 <td><font size="2">Unix and Windows. </font></td>
682 </tr>
683 <tr valign="top">
684 <td><b><font size="2">postgres7</font></b></td>
685 <td><font size="2">A</font></td>
686 <td><font size="2">PostgreSQL which supports LIMIT and other version 7 functionality.</font></td>
687 <td><font size="2">Y</font></td>
688 <td><font size="2">PostgreSQL client</font></td>
689 <td><font size="2">Unix and Windows. </font></td>
690 </tr>
691 <tr valign="top">
692 <td><b><font size="2">sapdb</font></b></td>
693 <td><font size="2">C</font></td>
694 <td><font size="2">SAP DB. Should work reliably as based on ODBC driver.</font></td>
695 <td><font size="2">Y/N</font></td>
696 <td><font size="2">SAP ODBC client</font></td>
697 <td> <p><font size="2">?</font></p></td>
698 </tr>
699 <tr valign="top">
700 <td><b><font size="2">sqlanywhere</font></b></td>
701 <td><font size="2">C</font></td>
702 <td><font size="2">Sybase SQL Anywhere. Should work reliably as based on ODBC
703 driver.</font></td>
704 <td><font size="2">Y/N</font></td>
705 <td><font size="2">SQL Anywhere ODBC client</font></td>
706 <td> <p><font size="2">?</font></p></td>
707 </tr>
708 <tr valign="top">
709 <td height="54"><b><font size="2">sqlite</font></b></td>
710 <td height="54"><font size="2">B</font></td>
711 <td height="54"><font size="2">SQLite. Only tested on PHP5.</font></td>
712 <td height="54"><font size="2">Y</font></td>
713 <td height="54"><font size="2">-</font></td>
714 <td height="54"> <p><font size="2">Unix and Windows.</font></p></td>
715 </tr>
716 <tr valign="top">
717 <td><b><font size="2">sybase</font></b></td>
718 <td><font size="2">C</font></td>
719 <td><font size="2">Sybase. </font></td>
720 <td><font size="2">Y/N</font></td>
721 <td><font size="2">Sybase client</font></td>
722 <td> <p><font size="2">Unix and Windows.</font></p></td>
723 </tr>
724 <p>
725 </table>
727 <p>The &quot;Tested&quot; column indicates how extensively the code has been tested
728 and used. <br>
729 A = well tested and used by many people<br>
730 B = tested and usable, but some features might not be implemented<br>
731 C = user contributed or experimental driver. Might not fully support all of
732 the latest features of ADOdb. </p>
733 <p>The column &quot;RecordCount() usable&quot; indicates whether RecordCount()
734 return the number of rows, or returns -1 when a SELECT statement is executed.
735 If this column displays Y/N then the RecordCount() is emulated when the global
736 variable $ADODB_COUNTRECS=true (this is the default). Note that for large recordsets,
737 it might be better to disable RecordCount() emulation because substantial amounts
738 of memory are required to cache the recordset for counting. Also there is a
739 speed penalty of 40-50% if emulation is required. This is emulated in most databases
740 except for PostgreSQL and MySQL. This variable is checked every time a query
741 is executed, so you can selectively choose which recordsets to count.</p>
742 <p>
743 <hr>
744 <h1>Tutorials<a name="quickstart"></a></h1>
745 <h3>Example 1: Select Statement<a name="ex1"></a></h3>
746 <p>Task: Connect to the Access Northwind DSN, display the first 2 columns of each
747 row.</p>
748 <p>In this example, we create a ADOConnection object, which represents the connection
749 to the database. The connection is initiated with <a href="#pconnect"><font face="Courier New, Courier, mono">PConnect</font></a>,
750 which is a persistent connection. Whenever we want to query the database, we
751 call the <font face="Courier New, Courier, mono">ADOConnection.<a href="#execute">Execute</a>()</font>
752 function. This returns an ADORecordSet object which is actually a cursor that
753 holds the current row in the array <font face="Courier New, Courier, mono">fields[]</font>.
754 We use <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font>
755 to move from row to row.</p>
756 <p>NB: A useful function that is not used in this example is <font face="Courier New, Courier, mono"><a href="#selectlimit">SelectLimit</a></font>,
757 which allows us to limit the number of rows shown.
758 <pre>
759 &lt;?
760 <font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php'); # load code common to ADOdb
761 $<font color="#660000">conn</font> = &amp;ADONewConnection('access'); # create a connection
762 $<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind DSN
763 $<font color="#660000">recordSet</font> = &amp;$<font color="#660000">conn</font>->Execute('select * from products');
764 if (!$<font color="#660000">recordSet</font>)
765 print $<font color="#660000">conn</font>-&gt;ErrorMsg();
766 else
767 <b>while</b> (!$<font color="#660000">recordSet</font>-&gt;EOF) &#123;
768 <b>print</b> $<font color="#660000">recordSet</font>->fields[0].' '.$<font color="#660000">recordSet</font>->fields[1].'&lt;BR&gt;';
769 $<font color="#660000">recordSet</font>-&gt;MoveNext();
770 &#125;</font><font face="Courier New, Courier, mono">
772 $<font color="#660000">recordSet</font>->Close(); # optional
773 $<font color="#660000">conn</font>->Close(); # optional
774 </font>
776 </pre>
777 <p>The $<font face="Courier New, Courier, mono">recordSet</font> returned stores
778 the current row in the <font face="Courier New, Courier, mono">$recordSet-&gt;fields</font>
779 array, indexed by column number (starting from zero). We use the <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font>
780 function to move to the next row. The <font face="Courier New, Courier, mono">EOF</font>
781 property is set to true when end-of-file is reached. If an error occurs in Execute(),
782 we return false instead of a recordset.</p>
783 <p>The <code>$recordSet-&gt;fields[]</code> array is generated by the PHP database
784 extension. Some database extensions only index by number and do not index the
785 array by field name. To force indexing by name - that is associative arrays
786 - use the SetFetchMode function. Each recordset saves and uses whatever fetch
787 mode was set when the recordset was created in Execute() or SelectLimit().
788 <pre>
789 $db->SetFetchMode(ADODB_FETCH_NUM);
790 $rs1 = $db->Execute('select * from table');
791 $db->SetFetchMode(ADODB_FETCH_ASSOC);
792 $rs2 = $db->Execute('select * from table');
793 print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i>
794 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>
795 </pre>
796 <p> </p>
797 <p>To get the number of rows in the select statement, you can use <font face="Courier New, Courier, mono">$recordSet-&gt;<a href="#recordcount">RecordCount</a>()</font>.
798 Note that it can return -1 if the number of rows returned cannot be determined.</p>
799 <h3>Example 2: Advanced Select with Field Objects<a name="ex2"></a></h3>
800 <p>Select a table, display the first two columns. If the second column is a date
801 or timestamp, reformat the date to US format.</p>
802 <pre>
803 &lt;?
804 <font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php'); # load code common to ADOdb
805 $<font color="#660000">conn</font> = &amp;ADONewConnection('access'); # create a connection
806 $<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn
807 $<font color="#660000">recordSet</font> = &amp;$<font color="#660000">conn</font>->Execute('select CustomerID,OrderDate from Orders');
808 if (!$<font color="#660000">recordSet</font>)
809 print $<font color="#660000">conn</font>-&gt;ErrorMsg();
810 else
811 <b>while</b> (!$<font color="#660000">recordSet</font>-&gt;EOF) &#123;
812 $<font color="#660000">fld</font> = <font color="#336600"><b>$</b><font color="#660000">recordSet</font><b>-&gt;FetchField</b></font><font color="#006600">(</font>1<font color="#006600">);</font>
813 $<font color="#660000">type</font> = <font color="#336600"><b>$</b><font color="#660000">recordSet</font><b>-&gt;MetaType</b></font>($fld-&gt;type);
815 <b>if</b> ( $<font color="#660000">type</font> == 'D' || $<font color="#660000">type</font> == 'T')
816 <b>print</b> $<font color="#660000">recordSet</font>-&gt;fields[0].' '.
817 <b><font color="#336600">$</font></b><font color="#660000">recordSet</font><b><font color="#336600">-&gt;UserDate</font></b>($<font color="#660000">recordSet</font>-&gt;fields[1],'<b>m/d/Y</b>').'&lt;BR&gt;';
818 <b>else </b>
819 <b>print</b> $<font color="#660000">recordSet</font>->fields[0].' '.$<font color="#660000">recordSet</font>->fields[1].'&lt;BR&gt;';
821 $<font color="#660000">recordSet</font>-&gt;MoveNext();
822 &#125;</font><font face="Courier New, Courier, mono">
823 $<font color="#660000">recordSet</font>->Close(); # optional
824 $<font color="#660000">conn</font>->Close(); # optional
825 </font>
827 </pre>
828 <p>In this example, we check the field type of the second column using <font face="Courier New, Courier, mono"><a href="#fetchfield">FetchField</a>().</font>
829 This returns an object with at least 3 fields.</p>
830 <ul>
831 <li><b>name</b>: name of column</li>
832 <li> <b>type</b>: native field type of column</li>
833 <li> <b>max_length</b>: maximum length of field. Some databases such as MySQL
834 do not return the maximum length of the field correctly. In these cases max_length
835 will be set to -1.</li>
836 </ul>
837 <p>We then use <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font>
838 to translate the native type to a <i>generic</i> type. Currently the following
839 <i>generic</i> types are defined:</p>
840 <ul>
841 <li><b>C</b>: character fields that should be shown in a &lt;input type=&quot;text&quot;&gt;
842 tag.</li>
843 <li><b>X</b>: TeXt, large text fields that should be shown in a &lt;textarea&gt;</li>
844 <li><b>B</b>: Blobs, or Binary Large Objects. Typically images.
845 <li><b>D</b>: Date field</li>
846 <li><b>T</b>: Timestamp field</li>
847 <li><b>L</b>: Logical field (boolean or bit-field)</li>
848 <li><b>I</b>:&nbsp; Integer field</li>
849 <li><b>N</b>: Numeric field. Includes autoincrement, numeric, floating point,
850 real and integer. </li>
851 <li><b>R</b>: Serial field. Includes serial, autoincrement integers. This works
852 for selected databases. </li>
853 </ul>
854 <p>If the metatype is of type date or timestamp, then we print it using the user
855 defined date format with <font face="Courier New, Courier, mono"><a href="#userdate">UserDate</a>(),</font>
856 which converts the PHP SQL date string format to a user defined one. Another
857 use for <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font>
858 is data validation before doing an SQL insert or update.</p>
859 <h3>Example 3: Inserting<a name="ex3"></a></h3>
860 <p>Insert a row to the Orders table containing dates and strings that need to
861 be quoted before they can be accepted by the database, eg: the single-quote
862 in the word <i>John's</i>.</p>
863 <pre>
864 &lt;?
865 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
866 $<font color="#660000">conn</font> = &amp;ADONewConnection('access'); # create a connection
868 $<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn
869 $<font color="#660000">shipto</font> = <font color="#006600"><b>$conn-&gt;qstr</b></font>(&quot;<i>John's Old Shoppe</i>&quot;);
871 $<font color="#660000">sql</font> = &quot;insert into orders (customerID,EmployeeID,OrderDate,ShipName) &quot;;
872 $<font color="#660000">sql</font> .= &quot;values ('ANATR',2,&quot;.<b><font color="#006600">$conn-&gt;DBDate(</font>time()<font color="#006600">)</font></b><font color="#006600">.</font>&quot;,$<font color="#660000">shipto</font>)&quot;;
874 <b>if</b> ($<font color="#660000">conn</font>->Execute($<font color="#660000">sql</font>) <font color="#336600"><b>=== false</b></font>) &#123;
875 <b>print</b> 'error inserting: '.<font color="#336600"><b>$conn-&gt;ErrorMsg()</b></font>.'&lt;BR&gt;';
876 &#125;
878 </pre>
879 <p>In this example, we see the advanced date and quote handling facilities of
880 ADOdb. The unix timestamp (which is a long integer) is appropriately formated
881 for Access with <font face="Courier New, Courier, mono"><a href="#dbdate">DBDate</a>()</font>,
882 and the right escape character is used for quoting the <i>John's Old Shoppe</i>,
883 which is<b> </b><i>John'<b>'</b>s Old Shoppe</i> and not PHP's default <i>John<b>'</b>s
884 Old Shoppe</i> with <font face="Courier New, Courier, mono"><a href="#qstr">qstr</a>()</font>.
885 </p>
886 <p>Observe the error-handling of the Execute statement. False is returned by<font face="Courier New, Courier, mono">
887 <a href="#execute">Execute</a>() </font>if an error occured. The error message
888 for the last error that occurred is displayed in <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font>.
889 Note: <i>php_track_errors</i> might have to be enabled for error messages to
890 be saved.</p>
891 <h3> Example 4: Debugging<a name="ex4"></a></h3>
892 <pre>&lt;?
893 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
894 $<font color="#663300">conn</font> = &amp;ADONewConnection('access'); # create a connection
895 $<font color="#663300">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn
896 <font color="#000000">$<font color="#663300">shipto</font> = <b>$conn-&gt;qstr</b>(&quot;John's Old Shoppe&quot;);
897 $<font color="#663300">sql</font> = &quot;insert into orders (customerID,EmployeeID,OrderDate,ShipName) &quot;;
898 $<font color="#663300">sql</font> .= &quot;values ('ANATR',2,&quot;.$<font color="#663300">conn</font>-&gt;FormatDate(time()).&quot;,$shipto)&quot;;
899 <b><font color="#336600">$<font color="#663300">conn</font>-&gt;debug = true;</font></b>
900 <b>if</b> ($<font color="#663300">conn</font>->Execute($sql) <b>=== false</b>) <b>print</b> 'error inserting';</font>
901 ?&gt;
902 </pre>
903 <p>In the above example, we have turned on debugging by setting <b>debug = true</b>.
904 This will display the SQL statement before execution, and also show any error
905 messages. There is no need to call <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font>
906 in this case. For displaying the recordset, see the <font face="Courier New, Courier, mono"><a href="#exrs2html">rs2html</a>()
907 </font>example.</p>
908 <p>Also see the section on <a href=#errorhandling>Custom Error Handlers</a>.</p>
909 <h3>Example 5: MySQL and Menus<a name="ex5"></a></h3>
910 <p>Connect to MySQL database <i>agora</i>, and generate a &lt;select&gt; menu
911 from an SQL statement where the &lt;option&gt; captions are in the 1st column,
912 and the value to send back to the server is in the 2nd column.</p>
913 <pre>&lt;?
914 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
915 $<font color="#663300">conn</font> = &amp;ADONewConnection('mysql'); # create a connection
916 $<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db
917 <font color="#000000">$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';
918 $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute($sql);
919 <b>print</b> <b><font color="#336600">$<font color="#663300">rs</font>-&gt;GetMenu('GetCust','Mary Rosli');
920 ?&gt;</font></b></font></pre>
921 <p>Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected.
922 See <a href="#getmenu"><font face="Courier New, Courier, mono">GetMenu</font></a><font face="Courier New, Courier, mono">()</font>.
923 We also have functions that return the recordset as an array: <font face="Courier New, Courier, mono"><a href="#getarray">GetArray</a>()</font>,
924 and as an associative array with the key being the first column: <a href="#getassoc1">GetAssoc</a>().</p>
925 <h3>Example 6: Connecting to 2 Databases At Once<a name="ex6"></a></h3>
926 <pre>&lt;?
927 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
928 $<font color="#663300">conn1</font> = &amp;ADONewConnection('mysql'); # create a mysql connection
929 $<font color="#663300">conn2</font> = &amp;ADONewConnection('oracle'); # create a oracle connection
931 $conn1-&gt;PConnect($server, $userid, $password, $database);
932 $conn2-&gt;PConnect(false, $ora_userid, $ora_pwd, $oraname);
934 $conn1-&gt;Execute('insert ...');
935 $conn2-&gt;Execute('update ...');
936 ?&gt;</pre>
937 <p>
938 <h3>Example 7: Generating Update and Insert SQL<a name="ex7"></a></h3>
939 ADOdb 1.31 and later supports two new recordset functions: GetUpdateSQL( ) and
940 GetInsertSQL( ). This allow you to perform a "SELECT * FROM table query WHERE...",
941 make a copy of the $rs->fields, modify the fields, and then generate the SQL to
942 update or insert into the table automatically.
943 <p> We show how the functions can be used when accessing a table with the following
944 fields: (ID, FirstName, LastName, Created).
945 <p> Before these functions can be called, you need to initialize the recordset
946 by performing a select on the table. Idea and code by Jonathan Younger jyounger#unilab.com.
947 <p>
948 <pre>&lt;?
949 #==============================================
950 # SAMPLE GetUpdateSQL() and GetInsertSQL() code
951 #==============================================
952 include('adodb.inc.php');
953 include('tohtml.inc.php');
955 #==========================
956 # This code tests an insert
958 $sql = "SELECT * FROM ADOXYZ WHERE id = -1";
959 # Select an empty record from the database
961 $conn = &ADONewConnection("mysql"); # create a connection
962 $conn->debug=1;
963 $conn->PConnect("localhost", "admin", "", "test"); # connect to MySQL, testdb
964 $rs = $conn->Execute($sql); # Execute the query and get the empty recordset
966 $record = array(); # Initialize an array to hold the record data to insert
968 # Set the values for the fields in the record
969 # Note that field names are case-insensitive
970 $record["firstname"] = "Bob";
971 $record["lastNamE"] = "Smith";
972 $record["creaTed"] = time();
974 # Pass the empty recordset and the array containing the data to insert
975 # into the GetInsertSQL function. The function will process the data and return
976 # a fully formatted insert sql statement.
977 $insertSQL = $conn->GetInsertSQL($rs, $record);
979 $conn->Execute($insertSQL); # Insert the record into the database
981 #==========================
982 # This code tests an update
984 $sql = "SELECT * FROM ADOXYZ WHERE id = 1";
985 # Select a record to update
987 $rs = $conn->Execute($sql); # Execute the query and get the existing record to update
989 $record = array(); # Initialize an array to hold the record data to update
991 # Set the values for the fields in the record
992 # Note that field names are case-insensitive
993 $record["firstname"] = "Caroline";
994 $record["LasTnAme"] = "Smith"; # Update Caroline's lastname from Miranda to Smith
996 # Pass the single record recordset and the array containing the data to update
997 # into the GetUpdateSQL function. The function will process the data and return
998 # a fully formatted update sql statement with the correct WHERE clause.
999 # If the data has not changed, no recordset is returned
1000 $updateSQL = $conn->GetUpdateSQL($rs, $record);
1002 $conn->Execute($updateSQL); # Update the record in the database
1003 $conn->Close();
1005 </pre>
1006 <h3>Example 8: Implementing Scrolling with Next and Previous<a name="ex8"></a></h3>
1007 <p> The following code creates a very simple recordset pager, where you can scroll
1008 from page to page of a recordset.</p>
1009 <pre>
1010 include_once('../adodb.inc.php');
1011 include_once('../adodb-pager.inc.php');
1012 session_start();
1014 $db = NewADOConnection('mysql');
1016 $db->Connect('localhost','root','','xphplens');
1018 $sql = "select * from adoxyz ";
1020 $pager = new ADODB_Pager($db,$sql);
1021 $pager->Render($rows_per_page=5);</pre>
1022 <p>This will create a basic record pager that looks like this: <a name="scr"></a>
1023 <p>
1024 <table border=1 bgcolor=beige>
1025 <tr>
1026 <td> <a href="#scr"><code>|&lt;</code></a> &nbsp; <a href="#scr"><code>&lt;&lt;</code></a>
1027 &nbsp; <a href="#scr"><code>>></code></a> &nbsp; <a href="#scr"><code>>|</code></a>
1028 &nbsp; </td>
1029 </tr>
1030 <tr>
1031 <td><TABLE COLS=4 width=100% border=1 bgcolor=white>
1032 <TH>ID</TH>
1033 <TH>First Name</TH>
1034 <TH>Last Name</TH>
1035 <TH>Date Created</TH>
1036 <TR>
1037 <TD align=right>36&nbsp;</TD>
1038 <TD>Alan&nbsp;</TD>
1039 <TD>Turing&nbsp;</TD>
1040 <TD>Sat 06, Oct 2001&nbsp;</TD>
1041 </TR>
1042 <TR>
1043 <TD align=right>37&nbsp;</TD>
1044 <TD>Serena&nbsp;</TD>
1045 <TD>Williams&nbsp;</TD>
1046 <TD>Sat 06, Oct 2001&nbsp;</TD>
1047 </TR>
1048 <TR>
1049 <TD align=right>38&nbsp;</TD>
1050 <TD>Yat Sun&nbsp;</TD>
1051 <TD>Sun&nbsp;</TD>
1052 <TD>Sat 06, Oct 2001&nbsp;</TD>
1053 </TR>
1054 <TR>
1055 <TD align=right>39&nbsp;</TD>
1056 <TD>Wai Hun&nbsp;</TD>
1057 <TD>See&nbsp;</TD>
1058 <TD>Sat 06, Oct 2001&nbsp;</TD>
1059 </TR>
1060 <TR>
1061 <TD align=right>40&nbsp;</TD>
1062 <TD>Steven&nbsp;</TD>
1063 <TD>Oey&nbsp;</TD>
1064 <TD>Sat 06, Oct 2001&nbsp;</TD>
1065 </TR>
1066 </TABLE></td>
1067 </tr>
1068 <tr>
1069 <td><font size=-1>Page 8/10</font></td>
1070 </tr>
1071 </table>
1072 <p>The number of rows to display at one time is controled by the Render($rows)
1073 method. If you do not pass any value to Render(), ADODB_Pager will default to
1074 10 records per page.
1075 <p>You can control the column titles by modifying your SQL (supported by most
1076 databases):
1077 <pre>$sql = 'select id as &quot;ID&quot;, firstname as &quot;First Name&quot;,
1078 lastname as &quot;Last Name&quot;, created as &quot;Date Created&quot; <br> from adoxyz';</pre>
1079 <p>The above code can be found in the <i>adodb/tests/testpaging.php</i> example
1080 included with this release, and the class ADODB_Pager in <i>adodb/adodb-pager.inc.php</i>.
1081 The ADODB_Pager code can be adapted by a programmer so that the text links can
1082 be replaced by images, and the dull white background be replaced with more interesting
1083 colors.
1084 <p>You can also allow display of html by setting $pager->htmlSpecialChars = false.
1085 <p>Some of the code used here was contributed by Iv&aacute;n Oliva and Cornel
1086 G. </p>
1087 <h3><a name="ex9"></a>Example 9: Exporting in CSV or Tab-Delimited Format</h3>
1088 <p>We provide some helper functions to export in comma-separated-value (CSV) and
1089 tab-delimited formats:</p>
1090 <pre><b>include_once('/path/to/adodb/toexport.inc.php');</b><br>include_once('/path/to/adodb/adodb.inc.php');<br>
1091 $db = &amp;NewADOConnection('mysql');<br>$db-&gt;Connect($server, $userid, $password, $database);<br><br>$rs = $db-&gt;Execute('select fname as &quot;First Name&quot;, surname as &quot;Surname&quot; from table');
1093 print &quot;&lt;pre&gt;&quot;;<br>print <b>rs2csv</b>($rs); # return a string, CSV format<p>print '&lt;hr&gt;';
1094 <br>$rs-&gt;MoveFirst(); # note, some databases do not support MoveFirst<br>print <b>rs2tab</b>($rs,<i>false</i>); # return a string, tab-delimited
1095 # false == suppress field names in first line</p>print '&lt;hr&gt;';<br>$rs-&gt;MoveFirst();<br><b>rs2tabout</b>($rs); # send to stdout directly (there is also an rs2csvout function)
1096 print &quot;&lt;/pre&gt;&quot;;
1098 $rs-&gt;MoveFirst();<br><b></b>$fp = fopen($path, &quot;w&quot;);
1099 if ($fp) {<br> <b>rs2csvfile</b>($rs, $fp); # write to file (there is also an rs2tabfile function)
1100 fclose($fp);<br>}
1101 </pre>
1102 <p> Carriage-returns or newlines are converted to spaces. Field names are returned
1103 in the first line of text. Strings containing the delimiter character are quoted
1104 with double-quotes. Double-quotes are double-quoted again. This conforms to
1105 Excel import and export guide-lines.
1106 <p>All the above functions take as an optional last parameter, $addtitles which
1107 defaults to <i>true</i>. When set to <i>false</i> field names in the first line
1108 are suppressed. <br>
1109 <h3>Example 10: Recordset Filters<a name="ex10"></a></h3>
1110 <p>Sometimes we want to pre-process all rows in a recordset before we use it.
1111 For example, we want to ucwords all text in recordset.
1112 <pre>
1113 include_once('adodb/rsfilter.inc.php');
1114 include_once('adodb/adodb.inc.php');
1116 // ucwords() every element in the recordset
1117 function do_ucwords(&$arr,$rs)
1118 &#123;
1119 foreach($arr as $k => $v) &#123;
1120 $arr[$k] = ucwords($v);
1121 &#125;
1122 &#125;
1124 $db = NewADOConnection('mysql');
1125 $db->PConnect('server','user','pwd','db');
1127 $rs = $db->Execute('select ... from table');
1128 $rs = <b>RSFilter</b>($rs,'do_ucwords');
1129 </pre>
1130 <p>The <i>RSFilter</i> function takes 2 parameters, the recordset, and the name
1131 of the <i>filter</i> function. It returns the processed recordset scrolled to
1132 the first record. The <i>filter</i> function takes two parameters, the current
1133 row as an array, and the recordset object. For future compatibility, you should
1134 not use the original recordset object. </p>
1135 <h3>Example 11:<a name="ex11"></a> Smart Transactions</h3>
1136 The old way of doing transactions required you to use
1137 <pre>
1138 $conn-><b>BeginTrans</b>();
1139 $ok = $conn->Execute($sql);
1140 if ($ok) $ok = $conn->Execute($sql2);
1141 if (!$ok) $conn-><b>RollbackTrans</b>();
1142 else $conn-><b>CommitTrans</b>();
1143 </pre>
1144 This is very complicated for large projects because you have to track the error
1145 status. Smart Transactions is much simpler. You start a smart transaction by calling
1146 StartTrans():
1147 <pre>
1148 $conn-><b>StartTrans</b>();
1149 $conn->Execute($sql);
1150 $conn->Execute($Sql2);
1151 $conn-><b>CompleteTrans</b>();
1152 </pre>
1153 CompleteTrans() detects when an SQL error occurs, and will Rollback/Commit as
1154 appropriate. To specificly force a rollback even if no error occured, use FailTrans().
1155 Note that the rollback is done in CompleteTrans(), and not in FailTrans().
1156 <pre>
1157 $conn-><b>StartTrans</b>();
1158 $conn->Execute($sql);
1159 if (!CheckRecords()) $conn-><strong>FailTrans</strong>();
1160 $conn->Execute($Sql2);
1161 $conn-><b>CompleteTrans</b>();
1162 </pre>
1163 <p>You can also check if a transaction has failed, using HasFailedTrans(), which
1164 returns true if FailTrans() was called, or there was an error in the SQL execution.
1165 Make sure you call HasFailedTrans() before you call CompleteTrans(), as it is
1166 only works between StartTrans/CompleteTrans.
1167 <p>Lastly, StartTrans/CompleteTrans is nestable, and only the outermost block
1168 is executed. In contrast, BeginTrans/CommitTrans/RollbackTrans is NOT nestable.
1169 <pre>
1170 $conn-><strong>StartTrans</strong>();
1171 $conn->Execute($sql);
1172 $conn-><strong>StartTrans</strong>(); <font color="#006600"># ignored</font>
1173 if (!CheckRecords()) $conn->FailTrans();
1174 $conn-><strong>CompleteTrans</strong>(); <font color="#006600"># ignored</font>
1175 $conn->Execute($Sql2);
1176 $conn-><strong>CompleteTrans</strong>();
1177 </pre>
1178 <p>Note: Savepoints are currently not supported.
1179 <h2><a name="errorhandling"></a>Using Custom Error Handlers and PEAR_Error</h2>
1180 Apart from the old $con->debug = true; way of debugging, ADOdb 1.50 onwards provides
1181 another way of handling errors using ADOdb's custom error handlers.
1182 <p> ADOdb provides two custom handlers which you can modify for your needs. The
1183 first one is in the <b>adodb-errorhandler.inc.php</b> file. This makes use of
1184 the standard PHP functions <a href=http://php.net/error_reporting>error_reporting</a>
1185 to control what error messages types to display, and <a href=http://php.net/trigger_error>trigger_error</a>
1186 which invokes the default PHP error handler.
1187 <p> Including the above file will cause <i>trigger_error($errorstring,E_USER_ERROR)</i>
1188 to be called when<br>
1189 (a) Connect() or PConnect() fails, or <br>
1190 (b) a function that executes SQL statements such as Execute() or SelectLimit()
1191 has an error.<br>
1192 (c) GenID() appears to go into an infinite loop.
1193 <p> The $errorstring is generated by ADOdb and will contain useful debugging information
1194 similar to the error.log data generated below. This file adodb-errorhandler.inc.php
1195 should be included before you create any ADOConnection objects.
1196 <p> If you define error_reporting(0), no errors will be passed to the error handler.
1197 If you set error_reporting(E_ALL), all errors will be passed to the error handler.
1198 You still need to use <b>ini_set("display_errors", "0" or "1")</b> to control
1199 the display of errors.
1200 <pre>
1201 &lt;?php
1202 <b>error_reporting(E_ALL); # pass any error messages triggered to error handler
1203 include('adodb-errorhandler.inc.php');</b>
1204 include('adodb.inc.php');
1205 include('tohtml.inc.php');
1206 $c = NewADOConnection('mysql');
1207 $c->PConnect('localhost','root','','northwind');
1208 $rs=$c->Execute('select * from productsz'); #invalid table productsz');
1209 if ($rs) rs2html($rs);
1211 </pre>
1212 <p> If you want to log the error message, you can do so by defining the following
1213 optional constants ADODB_ERROR_LOG_TYPE and ADODB_ERROR_LOG_DEST. ADODB_ERROR_LOG_TYPE
1214 is the error log message type (see <a href=http://php.net/error_log>error_log</a>
1215 in the PHP manual). In this case we set it to 3, which means log to the file
1216 defined by the constant ADODB_ERROR_LOG_DEST.
1217 <pre>
1218 &lt;?php
1219 <b>error_reporting(E_ALL); # report all errors
1220 ini_set("display_errors", "0"); # but do not echo the errors
1221 define('ADODB_ERROR_LOG_TYPE',3);
1222 define('ADODB_ERROR_LOG_DEST','C:/errors.log');
1223 include('adodb-errorhandler.inc.php');</b>
1224 include('adodb.inc.php');
1225 include('tohtml.inc.php');
1227 $c = NewADOConnection('mysql');
1228 $c->PConnect('localhost','root','','northwind');
1229 $rs=$c->Execute('select * from productsz'); ## invalid table productsz
1230 if ($rs) rs2html($rs);
1232 </pre>
1233 The following message will be logged in the error.log file:
1234 <pre>
1235 (2001-10-28 14:20:38) mysql error: [1146: Table 'northwind.productsz' doesn't exist] in
1236 EXECUTE("select * from productsz")
1237 </pre>
1238 The second error handler is <b>adodb-errorpear.inc.php</b>. This will create a
1239 PEAR_Error derived object whenever an error occurs. The last PEAR_Error object
1240 created can be retrieved using ADODB_Pear_Error().
1241 <pre>
1242 &lt;?php
1243 <b>include('adodb-errorpear.inc.php');</b>
1244 include('adodb.inc.php');
1245 include('tohtml.inc.php');
1246 $c = NewADOConnection('mysql');
1247 $c->PConnect('localhost','root','','northwind');
1248 $rs=$c->Execute('select * from productsz'); #invalid table productsz');
1249 if ($rs) rs2html($rs);
1250 else &#123;
1251 <b>$e = ADODB_Pear_Error();
1252 echo '&lt;p>',$e->message,'&lt;/p>';</b>
1253 &#125;
1255 </pre>
1256 <p> You can use a PEAR_Error derived class by defining the constant ADODB_PEAR_ERROR_CLASS
1257 before the adodb-errorpear.inc.php file is included. For easy debugging, you
1258 can set the default error handler in the beginning of the PHP script to PEAR_ERROR_DIE,
1259 which will cause an error message to be printed, then halt script execution:
1260 <pre>
1261 include('PEAR.php');
1262 PEAR::setErrorHandling('PEAR_ERROR_DIE');
1263 </pre>
1264 <p> Note that we do not explicitly return a PEAR_Error object to you when an error
1265 occurs. We return false instead. You have to call ADODB_Pear_Error() to get
1266 the last error or use the PEAR_ERROR_DIE technique.
1267 <h4>Error Messages</h4>
1268 <p>Error messages are outputted using the static method ADOConnnection::outp($msg,$newline=true).
1269 By default, it sends the messages to the client. You can override this to perform
1270 error-logging.
1271 <h2><a name="dsn"></a> Data Source Names</h2>
1272 <p>We now support connecting using PEAR style DSN's. A DSN is a connection string
1273 of the form:</p>
1274 <p>$dsn = <i>&quot;$driver://$username:$password@$hostname/$databasename&quot;</i>;</p>
1275 <p>You pass the DSN to the static class function DB::Connect. An example:</p>
1276 <pre> include_once('../adodb/adodb-pear.inc.php');
1277 $username = 'root';
1278 $password = '';
1279 $hostname = 'localhost';
1280 $databasename = 'xphplens';
1281 $driver = 'mysql';
1282 $dsn = &quot;$driver://$username:$password@$hostname/$databasename&quot;;</pre>
1283 <pre> $db = DB::Connect($dsn);<br> $rs = $db-&gt;Execute('select firstname,lastname from adoxyz');
1284 $cnt = 0;
1285 while ($arr = $rs-&gt;FetchRow()) {
1286 print_r($arr); print &quot;&lt;br&gt;&quot;;
1287 }</pre>
1288 <p>This requires PEAR to be installed and in the default include path in php.ini.</p>
1289 <h2><a name="caching"></a>Caching of Recordsets</h2>
1290 <p>ADOdb now supports caching of recordsets using the CacheExecute( ), CachePageExecute(
1291 ) and CacheSelectLimit( ) functions. There are similar to the non-cache functions,
1292 except that they take a new first parameter, $secs2cache.
1293 <p> An example:
1294 <pre>
1295 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
1296 $ADODB_CACHE_DIR = '/usr/ADODB_cache';
1297 $<font color="#663300">conn</font> = &amp;ADONewConnection('mysql'); # create a connection
1298 $<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db
1299 <font color="#000000">$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';
1300 $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->CacheExecute(15,$sql);</font></pre>
1301 <p><font color="#000000"> The first parameter is the number of seconds to cache
1302 the query. Subsequent calls to that query will used the cached version stored
1303 in $ADODB_CACHE_DIR. To force a query to execute and flush the cache, call CacheExecute()
1304 with the first parameter set to zero. Alternatively, use the CacheFlush($sql)
1305 call. </font></p>
1306 <p><font color="#000000">For the sake of security, we recommend you set <i>register_globals=off</i>
1307 in php.ini if you are using $ADODB_CACHE_DIR.</font></p>
1308 <p>In ADOdb 1.80 onwards, the secs2cache parameter is optional in CacheSelectLimit()
1309 and CacheExecute(). If you leave it out, it will use the $connection->cacheSecs
1310 parameter, which defaults to 60 minutes.
1311 <pre>
1312 $conn->Connect(...);
1313 $conn->cacheSecs = 3600*24; # cache 24 hours
1314 $rs = $conn->CacheExecute('select * from table');
1315 </pre>
1316 <p>Please note that magic_quotes_runtime should be turned off. <a href=http://phplens.com/lens/lensforum/msgs.php?LeNs#LensBM_forummsg>More
1317 info</a>. <font color="#000000">
1318 <h2><a name="pivot"></a>Pivot Tables</h2>
1319 </font> <p><font color="#000000">Since ADOdb 2.30, we support the generation of
1320 SQL to create pivot tables, also known as cross-tabulations. For further explanation
1321 read this DevShed <a href=http://www.devshed.com/Server_Side/MySQL/MySQLWiz/>Cross-Tabulation
1322 tutorial. We assume that your database supports the SQL case-when expression. </font></p>
1323 <font color="#000000">
1324 <p>In this example, we will use the Northwind database from Microsoft. In the
1325 database, we have a products table, and we want to analyze this table by <i>suppliers
1326 versus product categories</i>. We will place the suppliers on each row, and
1327 pivot on categories. So from the table on the left, we generate the pivot-table
1328 on the right:</p>
1329 </font>
1330 <table border="0" cellspacing="2" cellpadding="2" align="center">
1331 <tr>
1332 <td>
1333 <table border="1" cellspacing="2" cellpadding="2" align="center" width="142">
1334 <tr>
1335 <td><i>Supplier</i></td>
1336 <td><i>Category</i></td>
1337 </tr>
1338 <tr>
1339 <td>supplier1</td>
1340 <td>category1</td>
1341 </tr>
1342 <tr>
1343 <td>supplier2</td>
1344 <td>category1</td>
1345 </tr>
1346 <tr>
1347 <td>supplier2</td>
1348 <td>category2</td>
1349 </tr>
1350 </table>
1351 </td>
1352 <td> <font face="Courier New, Courier, mono">--&gt;</font></td>
1353 <td>
1354 <table border="1" cellspacing="2" cellpadding="2" align="center">
1355 <tr>
1356 <td>&nbsp;</td>
1357 <td><i>category1</i></td>
1358 <td><i>category2</i></td>
1359 <td><i>total</i></td>
1360 </tr>
1361 <tr>
1362 <td><i>supplier1</i></td>
1363 <td align="right">1</td>
1364 <td align="right">0</td>
1365 <td align="right">1</td>
1366 </tr>
1367 <tr>
1368 <td><i>supplier2</i></td>
1369 <td align="right">1</td>
1370 <td align="right">1</td>
1371 <td align="right">2</td>
1372 </tr>
1373 </table>
1374 </td>
1375 </tr>
1376 </table>
1377 <font color="#000000">
1378 <p>The following code will generate the SQL for a cross-tabulation:
1379 <pre>
1380 # Query the main "product" table
1381 # Set the rows to CompanyName
1382 # and the columns to the values of Categories
1383 # and define the joins to link to lookup tables
1384 # "categories" and "suppliers"
1386 include &quot;adodb/pivottable.php&quot;;
1387 $sql = PivotTableSQL(
1388 $gDB, # adodb connection
1389 'products p ,categories c ,suppliers s', # tables
1390 'CompanyName', # rows (multiple fields allowed)
1391 'CategoryName', # column to pivot on
1392 'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where
1394 </pre>
1395 </font>
1396 <p><font color="#000000"> This will generate the following SQL:</font></p>
1397 <p><code><font size="2">SELECT CompanyName, <br>
1398 SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS &quot;Beverages&quot;,
1399 <br>
1400 SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS &quot;Condiments&quot;,
1401 <br>
1402 SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS &quot;Confections&quot;,
1403 <br>
1404 SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS &quot;Dairy
1405 Products&quot;, <br>
1406 SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS &quot;Grains/Cereals&quot;,
1407 <br>
1408 SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS &quot;Meat/Poultry&quot;,
1409 <br>
1410 SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS &quot;Produce&quot;,
1411 <br>
1412 SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS &quot;Seafood&quot;,
1413 <br>
1414 SUM(1) as Total <br>
1415 FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID
1416 and s.SupplierID= p.SupplierID <br>
1417 GROUP BY CompanyName</font></code></p>
1418 <p> You can also pivot on <i>numerical columns</i> and <i>generate totals</i>
1419 by using ranges. <font color="#000000">This code was revised in ADODB 2.41
1420 and is not backward compatible.</font> The second example shows this:</p>
1421 <pre>
1422 $sql = PivotTableSQL(
1423 $gDB, # adodb connection
1424 'products p ,categories c ,suppliers s', # tables
1425 'CompanyName', #<font color="#000000"> rows (multiple fields allowed)</font>
1426 array( # column ranges
1427 ' 0 ' => 'UnitsInStock <= 0',
1428 "1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
1429 "6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
1430 "11 to 15" => '10 < UnitsInStock and UnitsInStock <= 15',
1431 "16+" => '15 < UnitsInStock'
1433 ' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
1434 'UnitsInStock', # sum this field
1435 'Sum ' # sum label prefix
1437 </pre>
1438 <p>Which generates: </p>
1439 <p> <code> <font size="2">SELECT CompanyName, <br>
1440 SUM(CASE WHEN UnitsInStock &lt;= 0 THEN UnitsInStock ELSE 0 END) AS &quot;Sum
1441 0 &quot;, <br>
1442 SUM(CASE WHEN 0 &lt; UnitsInStock and UnitsInStock &lt;= 5 THEN UnitsInStock
1443 ELSE 0 END) AS &quot;Sum 1 to 5&quot;,<br>
1444 SUM(CASE WHEN 5 &lt; UnitsInStock and UnitsInStock &lt;= 10 THEN UnitsInStock
1445 ELSE 0 END) AS &quot;Sum 6 to 10&quot;,<br>
1446 SUM(CASE WHEN 10 &lt; UnitsInStock and UnitsInStock &lt;= 15 THEN UnitsInStock
1447 ELSE 0 END) AS &quot;Sum 11 to 15&quot;, <br>
1448 SUM(CASE WHEN 15 &lt; UnitsInStock THEN UnitsInStock ELSE 0 END) AS &quot;Sum
1449 16+&quot;, <br>
1450 SUM(UnitsInStock) AS "Sum UnitsInStock", <br>
1451 SUM(1) as Total,<br>
1452 FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID
1453 and s.SupplierID= p.SupplierID <br>
1454 GROUP BY CompanyName</font></code><font size="2"><br>
1455 </font> </p>
1456 <font color="#000000"><hr>
1457 <h1>Class Reference<a name="ref"></a></h1>
1458 <p>Function parameters with [ ] around them are optional.</p>
1459 </font>
1460 <h2>Global Variables</h2>
1461 <h3><font color="#000000"><a name="adodb_countrecs"></a></font>$ADODB_COUNTRECS</h3>
1462 <p>If the database driver API does not support counting the number of records
1463 returned in a SELECT statement, the function RecordCount() is emulated when
1464 the global variable $ADODB_COUNTRECS is set to true, which is the default.
1465 We emulate this by buffering the records, which can take up large amounts
1466 of memory for big recordsets. Set this variable to false for the best performance.
1467 This variable is checked every time a query is executed, so you can selectively
1468 choose which recordsets to count.</p>
1469 <h3><font color="#000000"><a name="adodb_cache_dir"></a>$ADODB_CACHE_DIR</font></h3>
1470 <font color="#000000">
1471 <p>If you are using recordset caching, this is the directory to save your recordsets
1472 in. Define this before you call any caching functions such as CacheExecute(
1473 ). We recommend setting <i>register_globals=off</i> in php.ini if you use this
1474 feature for security reasons.</p>
1475 <p>If you are using Unix and apache, you might need to set your cache directory
1476 permissions to something similar to the following:</p>
1477 </font>
1478 <p>chown -R apache /path/to/adodb/cache<br>
1479 chgrp -R apache /path/to/adodb/cache </p>
1480 <font color="#000000">
1481 <h3><a name="adodb_ansi_padding_off"></a>$ADODB_ANSI_PADDING_OFF</h3>
1482 <p>Determines whether to right trim CHAR fields (and also VARCHAR for ibase/firebird).
1483 Set to true to trim. Default is false. Currently works for oci8po, ibase and firebird
1484 drivers. Added in ADOdb 4.01.
1485 <h3><font color="#000000"><a name="adodb_lang"></a></font>$ADODB_LANG</h3>
1486 <p>Determines the language used in MetaErrorMsg(). The default is 'en', for English.
1487 To find out what languages are supported, see the files
1488 in adodb/lang/adodb-$lang.inc.php, where $lang is the supported langauge.
1489 <h3><a name="adodb_fetch_mode"></a>$ADODB_FETCH_MODE</h3>
1490 <p>This is a global variable that determines how arrays are retrieved by recordsets.
1491 The recordset saves this value on creation (eg. in Execute( ) or SelectLimit(
1492 )), and any subsequent changes to $ADODB_FETCH_MODE have no affect on existing
1493 recordsets, only on recordsets created in the future.</p>
1494 <p>The following constants are defined:</p>
1495 </font>
1496 <p><font color="#000000">define('ADODB_FETCH_DEFAULT',0);<br>
1497 define('ADODB_FETCH_NUM',1);<br>
1498 define('ADODB_FETCH_ASSOC',2);<br>
1499 define('ADODB_FETCH_BOTH',3); </font></p>
1500 <font color="#000000">
1501 <p> An example:
1502 <pre>
1503 $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_NUM;
1504 $rs1 = $db->Execute('select * from table');
1505 $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_ASSOC;
1506 $rs2 = $db->Execute('select * from table');
1507 print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i>
1508 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>
1509 </pre>
1510 <p> As you can see in the above example, both recordsets store and use different
1511 fetch modes based on the $ADODB_FETCH_MODE setting when the recordset was
1512 created by Execute().</p>
1513 <p>If no fetch mode is predefined, the fetch mode defaults to ADODB_FETCH_DEFAULT.
1514 The behaviour of this default mode varies from driver to driver, so do not
1515 rely on ADODB_FETCH_DEFAULT. For portability, we recommend sticking to ADODB_FETCH_NUM
1516 or ADODB_FETCH_ASSOC. Many drivers do not support ADODB_FETCH_BOTH.</p>
1517 <p><strong>SetFetchMode Function</strong></p>
1518 <p>Some programmers prefer to use a more object-oriented solution, where the fetch
1519 mode is set by a object function, <a href="#setfetchmode">SetFetchMode</a>.
1520 Once this function is called for a connection object, that connection object
1521 will ignore the global variable $ADODB_FETCH_MODE and will use the internal
1522 fetchMode property exclusively.</p>
1523 <pre>
1524 $db->SetFetchMode(ADODB_FETCH_NUM);
1525 $rs1 = $db->Execute('select * from table');
1526 $db->SetFetchMode(ADODB_FETCH_ASSOC);
1527 $rs2 = $db->Execute('select * from table');
1528 print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i>
1529 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i></pre>
1530 <p>To retrieve the previous fetch mode, you can use check the $db-&gt;fetchMode
1531 property, or use the return value of SetFetchMode( ).
1532 <p><strong><a name="adodb_assoc_case"></a>ADODB_ASSOC_CASE</strong></p>
1533 <p>You can control the associative fetch case for certain drivers which behave
1534 differently. For the sybase, oci8po, mssql, odbc and ibase drivers and all
1535 drivers derived from them, ADODB_ASSOC_CASE will by default generate recordsets
1536 where the field name keys are lower-cased. Use the constant ADODB_ASSOC_CASE
1537 to change the case of the keys. There are 3 possible values:</p>
1538 <p>0 = assoc lowercase field names. $rs-&gt;fields['orderid']<br>
1539 1 = assoc uppercase field names. $rs-&gt;fields['ORDERID']<br>
1540 2 = use native-case field names. $rs-&gt;fields['OrderID'] -- this is the
1541 default since ADOdb 2.90</p>
1542 <p>To use it, declare it before you incldue adodb.inc.php.</p>
1543 <p>define('ADODB_ASSOC_CASE', 2); # use native-case for ADODB_FETCH_ASSOC<br>
1544 include('adodb.inc.php'); </p>
1545 <hr>
1546 <h2>ADOConnection<a name="adoconnection"></a></h2>
1547 <p>Object that performs the connection to the database, executes SQL statements
1548 and has a set of utility functions for standardising the format of SQL statements
1549 for issues such as concatenation and date formats.</p>
1550 <h3>ADOConnection Fields</h3>
1551 <p><b>databaseType</b>: Name of the database system we are connecting to. Eg.
1552 <b>odbc</b> or <b>mssql</b> or <b>mysql</b>.</p>
1553 <p><b>dataProvider</b>: The underlying mechanism used to connect to the database.
1554 Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</p>
1555 <p><b>host: </b>Name of server or data source name (DSN) to connect to.</p>
1556 <p><b>database</b>: Name of the database or to connect to. If ado is used, it
1557 will hold the ado data provider.</p>
1558 <p><b>user</b>: Login id to connect to database. Password is not saved for security
1559 reasons.</p>
1560 <p><b>raiseErrorFn</b>: Allows you to define an error handling function. See adodb-errorhandler.inc.php
1561 for an example.</p>
1562 <p><b>debug</b>: Set to <i>true</i> to make debug statements to appear.</p>
1563 <p><b>concat_operator</b>: Set to '+' or '||' normally. The operator used to concatenate
1564 strings in SQL. Used by the <b><a href="#concat">Concat</a></b> function.</p>
1565 <p><b>fmtDate</b>: The format used by the <b><a href="#dbdate">DBDate</a></b>
1566 function to send dates to the database. is '#Y-m-d#' for Microsoft Access,
1567 and ''Y-m-d'' for MySQL.</p>
1568 <p><b>fmtTimeStamp: </b>The format used by the <b><a href="#dbtimestamp">DBTimeStamp</a></b>
1569 function to send timestamps to the database. </p>
1570 <p><b>true</b>: The value used to represent true.Eg. '.T.'. for Foxpro, '1' for
1571 Microsoft SQL.</p>
1572 <p><b>false: </b> The value used to represent false. Eg. '.F.'. for Foxpro, '0'
1573 for Microsoft SQL.</p>
1574 <p><b>replaceQuote</b>: The string used to escape quotes. Eg. double single-quotes
1575 for Microsoft SQL, and backslash-quote for MySQL. Used by <a href="#qstr">qstr</a>.</p>
1576 <p><b>autoCommit</b>: indicates whether automatic commit is enabled. Default is
1577 true.</p>
1578 <p><b>charSet</b>: set the default charset to use. Currently only interbase supports
1579 this.</p>
1580 <p><b>dialect</b>: set the default sql dialect to use. Currently only interbase
1581 supports this.</p>
1582 <p><b>metaTablesSQL</b>: SQL statement to return a list of available tables. Eg.
1583 <i>SHOW TABLES</i> in MySQL.</p>
1584 <p><b>genID</b>: The latest id generated by GenID() if supported by the database.</p>
1585 <p><b>cacheSecs</b>: The number of seconds to cache recordsets if CacheExecute()
1586 or CacheSelectLimit() omit the $secs2cache parameter. Defaults to 60 minutes.</p>
1587 <p><b>sysDate</b>: String that holds the name of the database function to call
1588 to get the current date. Useful for inserts and updates.</p>
1589 <p><b>sysTimeStamp</b>: String that holds the name of the database function to
1590 call to get the current timestamp/datetime value.</p>
1591 <p><b>leftOuter</b>: String that holds operator for left outer join, if known.
1592 Otherwise set to false.</p>
1593 <p><b>rightOuter</b>: String that holds operator for left outer join, if known.
1594 Otherwise set to false.</p>
1595 <p><b>ansiOuter</b>: Boolean that if true indicates that ANSI style outer joins
1596 are permitted. Eg. <i>select * from table1 left join table2 on p1=p2.</i></p>
1597 <p><b>connectSID</b>: Boolean that indicates whether to treat the $database parameter
1598 in connects as the SID for the oci8 driver. Defaults to false. Useful for
1599 Oracle 8.0.5 and earlier.</p>
1600 <p><b>autoRollback</b>: Persistent connections are auto-rollbacked in PConnect(
1601 ) if this is set to true. Default is false.</p>
1602 <hr>
1603 <h3>ADOConnection Main Functions</h3>
1604 <p><b>ADOConnection( )</b></p>
1605 <p>Constructor function. Do not call this directly. Use ADONewConnection( ) instead.</p>
1606 <p><b>Connect<a name="connect"></a>($host,[$user],[$password],[$database])</b></p>
1607 <p>Non-persistent connect to data source or server $<b>host</b>, using userid
1608 $<b>user </b>and password $<b>password</b>. If the server supports multiple
1609 databases, connect to database $<b>database</b>. </p>
1610 <p>Returns true/false depending on connection.</p>
1611 <p>ADO Note: If you are using a Microsoft ADO and not OLEDB, you can set the $database
1612 parameter to the OLEDB data provider you are using.</p>
1613 <p>PostgreSQL: An alternative way of connecting to the database is to pass the
1614 standard PostgreSQL connection string in the first parameter $host, and the
1615 other parameters will be ignored.</p>
1616 <p>For Oracle and Oci8, there are two ways to connect. First is to use the TNS
1617 name defined in your local tnsnames.ora (or ONAMES or HOSTNAMES). Place the
1618 name in the $database field, and set the $host field to false. Alternatively,
1619 set $host to the server, and $database to the database SID, this bypassed
1620 tnsnames.ora.
1621 <p>Examples:
1622 <pre> # $oraname in tnsnames.ora/ONAMES/HOSTNAMES
1623 $conn->Connect(false, 'scott', 'tiger', $oraname);
1624 $conn->Connect('server:1521', 'scott', 'tiger', 'ServiceName'); # bypass tnsnames.ora</pre>
1625 <p>There are many examples of connecting to a database at <a href="http://php.weblogs.com/adodb">php.weblogs.com/ADOdb</a>,
1626 and in the testdatabases.inc.php file included in the release.</p>
1627 <p><b>PConnect<a name="pconnect"></a>($host,[$user],[$password],[$database])</b></p>
1628 <p>Persistent connect to data source or server $<b>host</b>, using userid $<b>user</b>
1629 and password $<b>password</b>. If the server supports multiple databases,
1630 connect to database $<b>database</b>.</p>
1631 <p>We now perform a rollback on persistent connection for selected databases since
1632 2.21, as advised in the PHP manual. See change log or source code for which
1633 databases are affected.
1634 <p>Returns true/false depending on connection. See Connect( ) above for more info.</p>
1635 <p>Since ADOdb 2.21, we also support autoRollback. If you set:</p>
1636 </font>
1637 <pre> $conn = &amp;NewADOConnection('mysql');
1638 $conn-&gt;autoRollback = true; # default is false
1639 $conn-&gt;PConnect(...); # rollback here</pre>
1640 <p> Then when doing a persistent connection with PConnect( ), ADOdb will
1641 perform a rollback first. This is because it is documented that PHP is
1642 not guaranteed to rollback existing failed transactions when
1643 persistent connections are used. This is implemented in Oracle,
1644 MySQL, PgSQL, MSSQL, ODBC currently.
1645 <p>Since ADOdb 3.11, you can force non-persistent
1646 connections even if PConnect is called by defining the constant
1647 ADODB_NEVER_PERSIST before you call PConnect.
1648 <p><b>NConnect<a name="nconnect"></a>($host,[$user],[$password],[$database])</b></p>
1649 <p>Always force a new connection. In contrast, PHP sometimes reuses connections
1650 when you use Connect() or PConnect(). Currently works only on mysql (PHP 4.3.0
1651 or later), postgresql and oci8-derived drivers. For other drivers, NConnect() works like
1652 Connect().
1653 <font color="#000000">
1654 <p><b>Execute<a name="execute"></a>($sql,$inputarr=false)</b></p>
1655 <p>Execute SQL statement $<b>sql</b> and return derived class of ADORecordSet
1656 if successful. Note that a record set is always returned on success, even
1657 if we are executing an insert or update statement. You can also pass in $sql a statement prepared
1658 in <a href=#prepare>Prepare()</a>.</p>
1659 <p>Returns derived class of ADORecordSet. Eg. if connecting via mysql, then ADORecordSet_mysql
1660 would be returned. False is returned if there was an error in executing the
1661 sql.</p>
1662 <p>The $inputarr parameter can be used for binding variables to parameters. Below
1663 is an Oracle example:</p>
1664 <pre>
1665 $conn->Execute("SELECT * FROM TABLE WHERE COND=:val", array('val'=> $val));
1666 </pre>
1667 <p>Another example, using ODBC,which uses the ? convention:</p>
1668 <pre>
1669 $conn->Execute("SELECT * FROM TABLE WHERE COND=?", array($val));
1670 </pre>
1671 <a name="binding"></a>
1672 <i>Binding variables</i><p>
1673 Variable binding speeds the compilation and caching of SQL statements, leading
1674 to higher performance. Currently Oracle, Interbase and ODBC supports variable binding.
1675 Interbase/ODBC style ? binding is emulated in databases that do not support binding.
1676 Note that you do not have to quote strings if you use binding.
1677 <p> Variable binding in the odbc, interbase and oci8po drivers.
1678 <pre>
1679 $rs = $db->Execute('select * from table where val=?', array('10'));
1680 </pre>
1681 Variable binding in the oci8 driver:
1682 <pre>
1683 $rs = $db->Execute('select name from table where val=:key',
1684 array('key' => 10));
1685 </pre>
1686 <a name="bulkbind"></a>
1687 <i>Bulk binding</i>
1688 <p>Since ADOdb 3.80, we support bulk binding in Execute(), in which you pass in a 2-dimensional array to
1689 be bound to an INSERT/UPDATE or DELETE statement.
1690 <pre>
1691 $arr = array(
1692 array('Ahmad',32),
1693 array('Zulkifli', 24),
1694 array('Rosnah', 21)
1696 $ok = $db->Execute('insert into table (name,age) values (?,?)',$arr);
1697 </pre>
1698 <p>This provides very high performance as the SQL statement is prepared first.
1699 The prepared statement is executed repeatedly for each array row until all rows are completed,
1700 or until the first error. Very useful for importing data.
1702 <p><b>CacheExecute<a name="cacheexecute"></a>([$secs2cache,]$sql,$inputarr=false)</b></p>
1703 <p>Similar to Execute, except that the recordset is cached for $secs2cache seconds
1704 in the $ADODB_CACHE_DIR directory, and $inputarr only accepts 1-dimensional arrays.
1705 If CacheExecute() is called again with the same $sql, $inputarr,
1706 and also the same database, same userid, and the cached recordset
1707 has not expired, the cached recordset is returned.
1708 <pre>
1709 include('adodb.inc.php');
1710 include('tohtml.inc.php');
1711 $ADODB_<b>CACHE_DIR</b> = '/usr/local/ADOdbcache';
1712 $conn = &ADONewConnection('mysql');
1713 $conn->PConnect('localhost','userid','password','database');
1714 $rs = $conn-><b>CacheExecute</b>(15, 'select * from table'); # cache 15 secs
1715 rs2html($rs); /* recordset to html table */
1716 </pre>
1717 <p> Alternatively, since ADOdb 1.80, the $secs2cache parameter is optional:</p>
1718 <pre> $conn-&gt;Connect(...);
1719 $conn-&gt;cacheSecs = 3600*24; // cache 24 hours
1720 $rs = $conn-&gt;CacheExecute('select * from table');
1721 </pre>
1722 If $secs2cache is omitted, we use the value
1723 in $connection-&gt;cacheSecs (default is 3600 seconds, or 1 hour). Use CacheExecute()
1724 only with SELECT statements.
1725 <p>Performance note: I have done some benchmarks and found that they vary so greatly
1726 that it's better to talk about when caching is of benefit. When your database
1727 server is <i>much slower </i>than your Web server or the database is <i>very
1728 overloaded </i>then ADOdb's caching is good because it reduces the load on
1729 your database server. If your database server is lightly loaded or much faster
1730 than your Web server, then caching could actually reduce performance. </p>
1731 <p><b>ExecuteCursor<a name="executecursor"></a>($sql,$cursorName='rs',$parameters=false)</b></p>
1732 <p>Execute an Oracle stored procedure, and returns an Oracle REF cursor variable as
1733 a regular ADOdb recordset. Does not work with any other database except oci8.
1734 Thanks to Robert Tuttle for the design.
1735 <pre>
1736 $db = ADONewConnection("oci8");
1737 $db->Connect("foo.com:1521", "uid", "pwd", "FOO");
1738 $rs = $db->ExecuteCursor("begin :cursorvar := getdata(:param1); end;",
1739 'cursorvar',
1740 array('param1'=>10));
1741 # $rs is now just like any other ADOdb recordset object<br> rs2html($rs);</pre>
1742 <p>ExecuteCursor() is a helper function that does the following internally:
1743 <pre>
1744 $stmt = $db->Prepare("BEGIN :RS := SP_FOO(); END;", true);
1745 $db->Parameter($stmt, $cur, 'RS', false, -1, OCI_B_CURSOR);
1746 $rs = $db->Execute($stmt);</pre>
1747 <p><b>SelectLimit<a name="selectlimit"></a>($sql,$numrows=-1,$offset=-1,$inputarr=false)</b></p>
1748 <p>Returns a recordset if successful. Returns false otherwise. Performs a select
1749 statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET
1750 $offset clause.</p>
1751 <p>In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records
1752 only. The equivalent is <code>$connection->SelectLimit('SELECT * FROM TABLE',3)</code>.
1753 This functionality is simulated for databases that do not possess this feature.</p>
1754 <p>And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg.
1755 after record 2, return 3 rows). The equivalent in ADOdb is <code>$connection->SelectLimit('SELECT
1756 * FROM TABLE',3,2)</code>.</p>
1757 <p>Note that this is the <i>opposite</i> of MySQL's LIMIT clause. You can also
1758 set <code>$connection->SelectLimit('SELECT * FROM TABLE',-1,10)</code> to
1759 get rows 11 to the last row.</p>
1760 <p>The last parameter $inputarr is for databases that support variable binding
1761 such as Oracle oci8. This substantially reduces SQL compilation overhead.
1762 Below is an Oracle example:</p>
1763 <pre>
1764 $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val));
1765 </pre>
1766 <p>The oci8po driver (oracle portable driver) uses the more standard bind variable
1767 of ?:
1768 <pre>
1769 $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val));
1770 </pre>
1771 <p>
1772 <p>Ron Wilson reports that SelectLimit does not work with UNIONs.
1773 <p><b>CacheSelectLimit<a name="cacheselectlimit"></a>([$secs2cache,] $sql, $numrows=-1,$offset=-1,$inputarr=false)</b></p>
1774 <p>Similar to SelectLimit, except that the recordset returned is cached for $secs2cache
1775 seconds in the $ADODB_CACHE_DIR directory. </p>
1776 <p>Since 1.80, $secs2cache has been optional, and you can define the caching time
1777 in $connection-&gt;cacheSecs.</p>
1778 </font>
1779 <pre><font color="#000000"> $conn-&gt;Connect(...);
1780 $conn-&gt;cacheSecs = 3600*24; // cache 24 hours
1781 $rs = $conn-&gt;CacheSelectLimit('select * from table',10);</font></pre>
1782 <font color="#000000">
1783 <p><b>CacheFlush<a name="cacheflush"></a>($sql=false,$inputarr=false)</b></p>
1784 <p>Flush (delete) any cached recordsets for the SQL statement $sql in $ADODB_CACHE_DIR.
1785 <p>If no parameter is passed in, then all adodb_*.cache files are deleted.
1786 <p> If you want to flush all cached recordsets manually, execute the following
1787 PHP code (works only under Unix): <br>
1788 <code> &nbsp; system(&quot;rm -f `find &quot;.$ADODB_CACHE_DIR.&quot; -name
1789 adodb_*.cache`&quot;);</code></p>
1790 <p>For general cleanup of all expired files, you should use <a href="http://www.superscripts.com/tutorial/crontab.html">crontab</a>
1791 on Unix, or at.exe on Windows, and a shell script similar to the following:<font face="Courier New, Courier, mono"><br>
1792 #------------------------------------------------------ <br>
1793 # This particular example deletes files in the TMPPATH <br>
1794 # directory with the string &quot;.cache&quot; in their name that <br>
1795 # are more than 7 days old. <br>
1796 #------------------------------------------------------ <br>
1797 AGED=7 <br>
1798 find ${TMPPATH} -mtime +$AGED | grep &quot;\.cache&quot; | xargs rm -f <br>
1799 </font> </p>
1800 <p><b>MetaError<a name="metaerror"></a>($errno=false)</b></p>
1801 <p>Returns a virtualized error number, based on PEAR DB's error number system. You might
1802 need to include adodb-error.inc.php before you call this function. The parameter $errno
1803 is the native error number you want to convert. If you do not pass any parameter, MetaError
1804 will call ErrorNo() for you and convert it. If the error number cannot be virtualized, MetaError
1805 will return -1 (DB_ERROR).</p>
1807 <p><b>MetaErrorMsg<a name="metaerrormsg"></a>($errno)</b></p>
1808 <p>Pass the error number returned by MetaError() for the equivalent textual error message.</p>
1809 <p><b>ErrorMsg<a name="errormsg"></a>()</b></p>
1810 <p>Returns the last status or error message. The error message is reset after every
1811 call to Execute().
1813 This can return a string even if
1814 no error occurs. In general you do not need to call this function unless an
1815 ADOdb function returns false on an error. </p>
1816 <p>Note: If <b>debug</b> is enabled, the SQL error message is always displayed
1817 when the <b>Execute</b> function is called.</p>
1818 <p><b>ErrorNo<a name="errorno"></a>()</b></p>
1819 <p>Returns the last error number. The error number is reset after every call to Execute().
1820 If 0 is returned, no error occurred.
1822 Note that old versions of PHP (pre 4.0.6) do
1823 not support error number for ODBC. In general you do not need to call this
1824 function unless an ADOdb function returns false on an error.</p>
1825 </font>
1826 <p><font color="#000000"><b>SetFetchMode<a name="setfetchmode"></a>($mode)</b></font></p>
1827 <p><font color="#000000">Sets the current fetch mode for the connection and stores
1828 it in $db-&gt;fetchMode. Legal modes are ADODB_FETCH_ASSOC and ADODB_FETCH_NUM.
1829 For more info, see <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>.</font></p>
1830 <p><font color="#000000">Returns the previous fetch mode, which could be false
1831 if SetFetchMode( ) has not been called before.</font></p>
1832 <font color="#000000">
1833 <p><b>CreateSequence<a name="createseq"></a>($seqName = 'adodbseq',$startID=1)</b></p>
1834 <p>Create a sequence. The next time GenID( ) is called, the value returned will
1835 be $startID. Added in 2.60.
1836 <p><b>DropSequenceD<a name="dropseq"></a>($seqName = 'adodbseq')</b></p>
1837 <p>Delete a sequence. Added in 2.60.
1838 <p><b>GenID<a name="genid"></a>($seqName = 'adodbseq',$startID=1)</b></p>
1839 <p>Generate a sequence number . Works for interbase,
1840 mysql, postgresql, oci8, oci8po, mssql, ODBC based (access,vfp,db2,etc) drivers
1841 currently. Uses $seqName as the name of the sequence. GenID() will automatically
1842 create the sequence for you if it does not exist (provided the userid has
1843 permission to do so). Otherwise you will have to create the sequence yourself.
1844 <p> If your database driver emulates sequences, the name of the table is the sequence
1845 name. The table has one column, "id" which should be of type integer, or if
1846 you need something larger - numeric(16).
1847 <p> For ODBC and databases that do not support sequences natively (eg mssql, mysql),
1848 we create a table for each sequence. If the sequence has not been defined
1849 earlier, it is created with the starting value set in $startID.</p>
1850 <p>Note that the mssql driver's GenID() before 1.90 used to generate 16 byte GUID's.</p>
1851 <p><b>UpdateBlob<a name="updateblob"></a>($table,$column,$val,$where)</b></p>
1852 Allows you to store a blob (in $val) into $table into $column in a row at $where.
1853 <p> Usage:
1854 <p>
1855 <pre>
1856 # for oracle
1857 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, empty_blob())');
1858 $conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');
1860 # non oracle databases
1861 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
1862 $conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');
1863 </pre>
1864 <p> Returns true if succesful, false otherwise. Supported by MySQL, PostgreSQL,
1865 Oci8, Oci8po and Interbase drivers. Other drivers might work, depending on
1866 the state of development.</p>
1867 <p>Note that when an Interbase blob is retrieved using SELECT, it still needs
1868 to be decoded using $connection->DecodeBlob($blob); to derive the original
1869 value in versions of PHP before 4.1.0.
1870 <p>For PostgreSQL, you can store your blob using blob oid's or as a bytea field.
1871 You can use bytea fields but not blob oid's currently with UpdateBlob( ).
1872 Conversely UpdateBlobFile( ) supports oid's, but not bytea data.<br>
1873 <br>
1874 If you do not pass in an oid, then UpdateBlob() assumes that you are storing
1875 in bytea fields.
1876 <p><b>UpdateClob<a name="updateclob"></a>($table,$column,$val,$where)</b></p>
1877 Allows you to store a clob (in $val) into $table into $column in a row at $where.
1878 Similar to UpdateBlob (see above), but for Character Large OBjects.
1879 <p> Usage:
1880 <pre>
1881 # for oracle
1882 $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, empty_clob())');
1883 $conn->UpdateBlob('clobtable','clobcol',$clobvalue,'id=1');
1885 # non oracle databases
1886 $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, null)');
1887 $conn->UpdateBlob('clobtable','clobcol',$clobvalue,'id=1');
1888 </pre>
1889 <p><b>UpdateBlobFile<a name="updateblobfile"></a>($table,$column,$path,$where,$blobtype='BLOB')</b></p>
1890 <p>Similar to UpdateBlob, except that we pass in a file path to where the blob
1891 resides.
1892 <p>For PostgreSQL, if you are using blob oid's, use this interface. This interface
1893 does not support bytea fields.
1894 <p>Returns true if successful, false otherwise.
1895 <p><b>BlobEncode<a name="blobencode" id="blobencode"></a>($blob)</b>
1896 <p>Some databases require blob's to be encoded manually before upload. Note if
1897 you use UpdateBlob( ) or UpdateBlobFile( ) the conversion is done automatically
1898 for you and you do not have to call this function. For PostgreSQL, currently,
1899 BlobEncode() can only be used for bytea fields.
1900 <p>Returns the encoded blob value.
1901 <p>Note that there is a connection property called <em>blobEncodeType</em> which
1902 has 3 legal values:
1903 <p>false - no need to perform encoding or decoding.<br>
1904 'I' - blob encoding required, and returned encoded blob is a numeric value
1905 (no need to quote).<br>
1906 'C' - blob encoding required, and returned encoded blob is a character value
1907 (requires quoting).
1908 <p>This is purely for documentation purposes, so that programs that accept multiple
1909 database drivers know what is the right thing to do when processing blobs.
1910 <p><strong>BlobDecode<a name="blobdecode"></a>($blob)</strong>
1911 </font><p><font color="#000000">Some databases require blob's to be decoded manually after doing a select statement.
1912 If the database does not require decoding, then this function will return
1913 the blob unchanged. Currently BlobDecode is only required for one database,
1914 PostgreSQL, and only if you are using blob oid's (if you are using bytea fields,
1915 we auto-decode for you).</font><font color="#000000">
1916 <pre>$rs = $db-&gt;Execute(&quot;select bloboid from postgres_table where id=$key&quot;);
1917 $blob = $db-&gt;BlobDecode( reset($rs-&gt;fields) );</pre>
1918 <p><b>Replace<a name="replace"></a>($table, $arrFields, $keyCols,$autoQuote=false)</b></p>
1919 <p>Try to update a record, and if the record is not found, an insert statement
1920 is generated and executed. Returns 0 on failure, 1 if update statement worked,
1921 2 if no record was found and the insert was executed successfully. This differs
1922 from MySQL's replace which deletes the record and inserts a new record. This
1923 also means you cannot update the primary key. The only exception to this is
1924 Interbase and its derivitives, which uses delete and insert because of some
1925 Interbase API limitations.
1926 <p>The parameters are $table which is the table name, the $keyCols which is an
1927 associative array where the keys are the field names, and keyCols is the name
1928 of the primary key, or an array of field names if it is a compound key. If
1929 $autoQuote is set to true, then Replace() will quote all values that are non-numeric;
1930 auto-quoting will not quote nulls. Note that auto-quoting will not work if
1931 you use SQL functions or operators.
1932 <p>Examples:
1933 <pre>
1934 # single field primary key
1935 $ret = $db->Replace('atable',
1936 array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),
1937 'id',$autoquote = true);
1938 # generates UPDATE atable SET firstname='Harun',lastname='Al-Rashid' WHERE id=1000
1939 # or INSERT INTO atable (id,firstname,lastname) VALUES (1000,'Harun','Al-Rashid')
1941 # compound key
1942 $ret = $db->Replace('atable2',
1943 array('firstname'=>'Harun','lastname'=>'Al-Rashid', 'age' => 33, 'birthday' => 'null'),
1944 array('lastname','firstname'),
1945 $autoquote = true);
1947 # no auto-quoting
1948 $ret = $db->Replace('atable2',
1949 array('firstname'=>"'Harun'",'lastname'=>"'Al-Rashid'", 'age' => 'null'),
1950 array('lastname','firstname'));
1951 </pre>
1952 <p><b>GetUpdateSQL<a name="getupdatesql"></a>(&$rs, $arrFields, $forceUpdate=false,$magicq=false)</b></p>
1953 <p>Generate SQL to update a table given a recordset $rs, and the modified fields
1954 of the array $arrFields (which must be an associative array holding the column
1955 names and the new values) are compared with the current recordset. If $forceUpdate
1956 is true, then we also generate the SQL even if $arrFields is identical to
1957 $rs-&gt;fields. Requires the recordset to be associative. $magicq is used
1958 to indicate whether magic quotes are enabled (see qstr()). The field names in the array
1959 are case-insensitive.</p>
1960 <p>Since 3.61, define('ADODB_FORCE_NULLS',1) and all PHP nulls will be auto-converted to SQL nulls.
1961 <p><b>GetInsertSQL<a name="getinsertsql"></a>(&$rs, $arrFields,$magicq=false)</b></p>
1962 <p>Generate SQL to insert into a table given a recordset $rs. Requires the query
1963 to be associative. $magicq is used to indicate whether magic quotes are enabled
1964 (for qstr()). The field names in the array are case-insensitive.</p>
1966 <p>Since 3.61, define('ADODB_FORCE_NULLS',1) and all PHP nulls will be auto-converted
1967 to SQL nulls.
1968 <p><b>PageExecute<a name="pageexecute"></a>($sql, $nrows, $page, $inputarr=false)</b>
1969 <p>Used for pagination of recordset. $page is 1-based. See <a href="#ex8">Example
1970 8</a>.</p>
1971 </font>
1972 <p><font color="#000000"><b>CachePageExecute<a name="cachepageexecute"></a>($secs2cache,
1973 $sql, $nrows, $page, $inputarr=false)</b> </font></p>
1974 <p><font color="#000000">Used for pagination of recordset. $page is 1-based. See
1975 <a href="#ex8">Example 8</a>. Caching version of PageExecute.</font></p>
1976 <font color="#000000">
1977 <p></p>
1978 <p><b>Close<a name="close"></a>( )</b></p>
1979 <p>Close the database connection. PHP4 proudly states that we no longer have to
1980 clean up at the end of the connection because the reference counting mechanism
1981 of PHP4 will automatically clean up for us.</p>
1982 <p><b>StartTrans<a name="starttrans"></a>( )</b></p>
1983 <p>Start a monitored transaction. As SQL statements are executed, ADOdb will monitor
1984 for SQL errors, and if any are detected, when CompleteTrans() is called, we auto-rollback.
1986 <p> To understand why StartTrans() is superior to BeginTrans(),
1987 let us examine a few ways of using BeginTrans().
1988 The following is the wrong way to use transactions:
1989 <pre>
1990 $DB->BeginTrans();
1991 $DB->Execute("update table1 set val=$val1 where id=$id");
1992 $DB->Execute("update table2 set val=$val2 where id=$id");
1993 $DB->CommitTrans();
1994 </pre>
1995 <p>because you perform no error checking. It is possible to update table1 and
1996 for the update on table2 to fail. Here is a better way:
1997 <pre>
1998 $DB->BeginTrans();
1999 $ok = $DB->Execute("update table1 set val=$val1 where id=$id");
2000 if ($ok) $ok = $DB->Execute("update table2 set val=$val2 where id=$id");
2001 if ($ok) $DB->CommitTrans();
2002 else $DB->RollbackTrans();
2003 </pre>
2004 <p>Another way is (since ADOdb 2.0):
2005 <pre>
2006 $DB->BeginTrans();
2007 $ok = $DB->Execute("update table1 set val=$val1 where id=$id");
2008 if ($ok) $ok = $DB->Execute("update table2 set val=$val2 where id=$id");
2009 $DB->CommitTrans($ok);
2010 </pre>
2011 <p> Now it is a headache monitoring $ok all over the place. StartTrans() is an
2012 improvement because it monitors all SQL errors for you. This is particularly
2013 useful if you are calling black-box functions in which SQL queries might be executed.
2014 Also all BeginTrans, CommitTrans and RollbackTrans calls inside a StartTrans block
2015 will be disabled, so even if the black box function does a commit, it will be ignored.
2016 <pre>
2017 $DB->StartTrans();
2018 CallBlackBox();
2019 $DB->Execute("update table1 set val=$val1 where id=$id");
2020 $DB->Execute("update table2 set val=$val2 where id=$id");
2021 $DB->CompleteTrans($ok);
2022 </pre>
2023 <p>Note that a StartTrans blocks are nestable, the inner blocks are ignored.
2024 <p><b>CompleteTrans<a name="completetrans"></a>($autoComplete=true)</b></p>
2025 <p>Complete a transaction called with StartTrans(). This function monitors
2026 for SQL errors, and will commit if no errors have occured, otherwise it will rollback.
2027 Returns true on commit, false on rollback. If the parameter $autoComplete is true
2028 monitor sql errors and commit and rollback as appropriate. Set $autoComplete to false
2029 to force rollback even if no SQL error detected.
2030 <p><b>FailTrans<a name="failtrans"></a>( )</b></p>
2031 <p>Fail a transaction started with StartTrans(). The rollback will only occur when
2032 CompleteTrans() is called.
2033 <p><b>HasFailedTrans<a name="hasfailedtrans"></a>( )</b></p>
2034 <p>Check whether smart transaction has failed,
2035 eg. returns true if there was an error in SQL execution or FailTrans() was called.
2036 If not within smart transaction, returns false.
2037 <p><b>BeginTrans<a name="begintrans"></a>( )</b></p>
2038 <p>Begin a transaction. Turns off autoCommit. Returns true if successful. Some
2039 databases will always return false if transaction support is not available.
2040 Any open transactions will be rolled back when the connection is closed. Among the
2041 databases that support transactions are Oracle, PostgreSQL, Interbase, MSSQL, certain
2042 versions of MySQL, DB2, Informix, Sybase, etc.</p>
2043 <p>Note that <a href=#starttrans>StartTrans()</a> and CompleteTrans() is a superior method of
2044 handling transactions, available since ADOdb 3.40. For a explanation, see the <a href=#starttrans>StartTrans()</a> documentation.
2046 <p>You can also use the ADOdb <a href=#errorhandling>error handler</a> to die
2047 and rollback your transactions for you transparently. Some buggy database extensions
2048 are known to commit all outstanding tranasactions, so you might want to explicitly
2049 do a $DB->RollbackTrans() in your error handler for safety.
2050 <h4>Detecting Transactions</h4>
2051 <p>Since ADOdb 2.50, you are able to detect when you are inside a transaction. Check
2052 that $connection->transCnt > 0. This variable is incremented whenever BeginTrans() is called,
2053 and decremented whenever RollbackTrans() or CommitTrans() is called.
2054 <p><b>CommitTrans<a name="committrans"></a>($ok=true)</b></p>
2055 <p>End a transaction successfully. Returns true if successful. If the database
2056 does not support transactions, will return true also as data is always committed.
2057 </p>
2058 <p>If you pass the parameter $ok=false, the data is rolled back. See example in
2059 BeginTrans().</p>
2060 <p><b>RollbackTrans<a name="rollbacktrans"></a>( )</b></p>
2061 <p>End a transaction, rollback all changes. Returns true if successful. If the
2062 database does not support transactions, will return false as data is never rollbacked.
2063 </p>
2064 </font><font color="#000000">
2065 <p><b>GetAssoc<a name=getassoc1></a>($sql,$inputarr=false,$force_array=false,$first2cols=false)</b></p>
2066 <p>Returns an associative array for the given query $sql with optional bind parameters
2067 in $inputarr. If the number of columns returned is greater to two, a 2-dimensional
2068 array is returned, with the first column of the recordset becomes the keys
2069 to the rest of the rows. If the columns is equal to two, a 1-dimensional array
2070 is created, where the the keys directly map to the values (unless $force_array
2071 is set to true, when an array is created for each value).
2072 <p> <font color="#000000">Examples:<a name=getassocex></a></font></p>
2073 </font>
2074 <p><font color="#000000">We have the following data in a recordset:</font></p>
2075 <p><font color="#000000">row1: Apple, Fruit, Edible<br>
2076 row2: Cactus, Plant, Inedible<br>
2077 row3: Rose, Flower, Edible</font></p>
2078 <p><font color="#000000">GetAssoc will generate the following 2-dimensional associative
2079 array:</font></p>
2080 <p><font color="#000000">Apple =&gt; array[Fruit, Edible]<br>
2081 Cactus =&gt; array[Plant, Inedible]<br>
2082 Rose =&gt; array[Flower,Edible]</font></p>
2083 <p><font color="#000000">If the dataset is:</font></p>
2084 <p><font color="#000000"><font color="#000000"><font color="#000000">row1: Apple,
2085 Fruit<br>
2086 row2: Cactus, Plant<br>
2087 row3: Rose, Flower</font> </font></font></p>
2088 <p><font color="#000000"><font color="#000000">GetAssoc will generate the following
2089 1-dimensional associative array (with $force_array==false):</font></font></p>
2090 <p><font color="#000000">Apple =&gt; Fruit</font><br>
2091 Cactus=&gt;Plant<br>
2092 Rose=&gt;Flower <font color="#000000"><font color="#000000"> </font></font><font color="#000000"><font color="#000000"></font></font></p>
2093 <p><font color="#000000">The function returns:</font></p>
2094 <p><font color="#000000">The associative array, or false if an error occurs.</font></p>
2095 <font color="#000000">
2096 <p><b>CacheGetAssoc<a name="cachegetassoc"></a>([$secs2cache,] $sql,$inputarr=false,$force_array=false,$first2cols=false)</b></p>
2097 </font><font color="#000000">
2098 <p>Caching version of <a href=#getassoc1>GetAssoc</a> function above.
2099 <p><b>GetOne<a name="getone"></a>($sql,$inputarr=false)</b></p>
2100 <p>Executes the SQL and returns the first field of the first row. The recordset
2101 and remaining rows are discarded for you automatically. If an error occur, false
2102 is returned.</p>
2103 <p><b>GetRow<a name="getrow"></a>($sql,$inputarr=false)</b></p>
2104 <p>Executes the SQL and returns the first row as an array. The recordset and remaining
2105 rows are discarded for you automatically. If an error occurs, false is returned.</p>
2106 <p><b>GetAll<a name="getall"></a>($sql)</b></p>
2107 </font>
2108 <p><font color="#000000">Executes the SQL and returns the all the rows as a 2-dimensional
2109 array. The recordset is discarded for you automatically. If an error occurs,
2110 false is returned.</font></p>
2111 <p><b>GetCol<a name="getcol"></a>($sql,$inputarr=false,$trim=false)</b></p>
2113 <p><font color="#000000">Executes the SQL and returns all elements of the first column as a
2114 1-dimensional array. The recordset is discarded for you automatically. If an error occurs,
2115 false is returned.</font></p>
2116 <p><font color="#000000"><b>CacheGetOne<a name="cachegetone"></a>([$secs2cache,]
2117 $sql,$inputarr=false), CacheGetRow<a name="cachegetrow"></a>([$secs2cache,] $sql,$inputarr=false), CacheGetAll<a name="cachegetall"></a>([$secs2cache,]
2118 $sql,$inputarr=false), CacheGetCol<a name="cachegetcol"></a>([$secs2cache,]
2119 $sql,$inputarr=false,$trim=false)</b></font></p>
2120 <font color="#000000">
2121 <p>Similar to above Get* functions, except that the recordset is serialized and
2122 cached in the $ADODB_CACHE_DIR directory for $secs2cache seconds. Good for speeding
2123 up queries on rarely changing data. Note that the $secs2cache parameter is optional.
2124 If omitted, we use the value in $connection-&gt;cacheSecs (default is 3600 seconds,
2125 or 1 hour).</p>
2126 <p><b>Prepare<a name="prepare"></a>($sql )</b></p>
2127 </font>
2128 <p><font color="#000000">Prepares (compiles) an SQL query for repeated execution. Bind parameters
2129 are denoted by ?, except for the oci8 driver, which uses the traditional Oracle :varname
2130 convention.
2131 </font></p>
2132 <p><font color="#000000">Returns an array containing the original sql statement
2133 in the first array element; the remaining elements of the array are driver dependent.
2134 If there is an error, or we are emulating Prepare( ), we return the original
2135 $sql string. This is because all error-handling has been centralized in Execute(
2136 ).</font></p>
2137 <p><font color="#000000">Prepare( ) cannot be used with functions that use SQL
2138 query rewriting techniques, e.g. PageExecute( ) and SelectLimit( ).</font></p>
2139 <p>Example:</p>
2140 <pre><font color="#000000">$stmt = $DB-&gt;Prepare('insert into table (col1,col2) values (?,?)');
2141 for ($i=0; $i &lt; $max; $i++)<br></font> $DB-&gt;<font color="#000000">Execute($stmt,array((string) rand(), $i));
2142 </font></pre>
2143 <font color="#000000">
2144 <p>Also see InParameter(), OutParameter() and PrepareSP() below. Only supported internally by interbase,
2145 oci8 and selected ODBC-based drivers, otherwise it is emulated. There is no
2146 performance advantage to using Prepare() with emulation.
2147 <p> Important: Due to limitations or bugs in PHP, if you are getting errors when
2148 you using prepared queries, try setting $ADODB_COUNTRECS = false before preparing.
2149 This behaviour has been observed with ODBC.
2150 <p><b>IfNull<a name="ifnull"></a>($field, $nullReplacementValue)</b></p>
2151 <p>Portable IFNULL function (NVL in Oracle). Returns a string that represents
2152 the function that checks whether a $field is null for the given database, and
2153 if null, change the value returned to $nullReplacementValue. Eg.</p>
2154 <pre>$sql = <font color="#993300">'SELECT '</font>.$db-&gt;IfNull('name', <font color="#993300">&quot;'- unknown -'&quot;</font>).<font color="#993300"> ' FROM table'</font>;</pre>
2156 <p><b>length<a name="length"></a></b></p>
2157 <p>This is not a function, but a property. Some databases have "length" and others "len"
2158 as the function to measure the length of a string. To use this property:
2159 <pre>
2160 $sql = <font color="#993300">"SELECT "</font>.$db->length.<font color="#993300">"(field) from table"</font>;
2161 $rs = $db->Execute($sql);
2162 </pre>
2164 <p><b>random<a name="random"></a></b></p>
2165 <p>This is not a function, but a property. This is a string that holds the sql to
2166 generate a random number between 0.0 and 1.0 inclusive.
2168 <p><b>substr<a name="substr"></a></b></p>
2169 <p>This is not a function, but a property. Some databases have "substr" and others "substring"
2170 as the function to retrieve a sub-string. To use this property:
2171 <pre>
2172 $sql = <font color="#993300">"SELECT "</font>.$db->substr.<font color="#993300">"(field, $offset, $length) from table"</font>;
2173 $rs = $db->Execute($sql);
2174 </pre>
2175 <p>For all databases, the 1st parameter of <i>substr</i> is the field, the 2nd is the
2176 offset (1-based) to the beginning of the sub-string, and the 3rd is the length of the sub-string.
2179 <p><b>Param<a name="param"></a>($name )</b></p>
2180 <p>Generates a bind placeholder portably. For most databases, the bind placeholder
2181 is "?". However some databases use named bind parameters such as Oracle, eg
2182 ":somevar". This allows us to portably define an SQL statement with bind parameters:
2183 <pre><font color="#000000">$sql = <font color="#993300">'insert into table (col1,col2) values ('</font>.$DB-&gt;Param('a').<font color="#993300">','</font>.$DB-&gt;Param('b').<font color="#993300">')'</font>;
2184 <font color="#006600"># generates 'insert into table (col1,col2) values (?,?)'
2185 # or 'insert into table (col1,col2) values (:a,:b)</font>'
2186 $stmt = $DB-&gt;Prepare($sql);
2187 $stmt = $DB-&gt;Execute($stmt,array('one','two'));
2188 </font></pre>
2189 <font color="#000000">
2190 <p></p>
2191 <p><b>PrepareSP</b><b><a name="preparesp"></a></b><b>($sql)</b></p>
2192 <p>When calling stored procedures in mssql and oci8 (oracle), and you might want
2193 to directly bind to parameters that return values, or for special LOB handling.
2194 PrepareSP() allows you to do so.
2195 <p>Returns the same array or $sql string as Prepare( ) above. If you do not need
2196 to bind to return values, you should use Prepare( ) instead.</p>
2197 <p>For examples of usage of PrepareSP( ), see InParameter( ) below.
2198 <p>Note: in the mssql driver, preparing stored procedures requires a special function
2199 call, mssql_init( ), which is called by this function. PrepareSP( ) is available
2200 in all other drivers, and is emulated by calling Prepare( ). </p>
2201 <p><b> InParameter<a name="inparameter"></a>($stmt, $var, $name,
2202 $maxLen = 4000, $type = false )</b></p>
2203 Binds a PHP variable as input to a stored procedure variable. The parameter <i>$stmt</i>
2204 is the value returned by PrepareSP(), <i>$var</i> is the PHP variable you want to bind, $name
2205 is the name of the stored procedure variable. Optional is <i>$maxLen</i>, the maximum length of the
2206 data to bind, and $type which is database dependant.
2207 Consult <a href=http://php.net/mssql_bind>mssql_bind</a> and <a href=http://php.net/ocibindbyname>ocibindbyname</a> docs
2208 at php.net for more info on legal values for $type.
2210 InParameter() is a wrapper function that calls Parameter() with $isOutput=false.
2211 The advantage of this function is that it is self-documenting, because
2212 the $isOutput parameter is no longer needed. Only for mssql
2213 and oci8 currently.
2214 <p>Here is an example using oci8:
2215 <pre><font color="green"># For oracle, Prepare and PrepareSP are identical</font>
2216 $stmt = $db-&gt;PrepareSP(
2217 <font color="#993300">&quot;declare RETVAL integer;
2218 begin
2219 :RETVAL := </font><font color="#993300">SP_RUNSOMETHING</font><font color="#993300">(:myid,:group);
2220 end;&quot;</font>);
2221 $db-&gt;InParameter($stmt,$id,'myid');
2222 $db-&gt;InParameter($stmt,$group,'group',64);
2223 $db-&gt;OutParameter($stmt,$ret,'RETVAL');<br>$db-&gt;Execute($stmt);
2224 </pre>
2225 <p> The same example using mssql:</p>
2226 </font>
2227 <pre><font color="#000000"><font color="green"># @RETVAL = SP_RUNSOMETHING @myid,@group</font>
2228 $stmt = $db-&gt;PrepareSP(<font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font>); <br><font color="green"># note that the parameter name does not have @ in front!</font>
2229 $db-&gt;InParameter($stmt,$id,'myid');
2230 $db-&gt;InParameter($stmt,$group,'group',64);
2231 <font color="green"># return value in mssql - RETVAL is hard-coded name</font>
2232 $db-&gt;OutParameter($stmt,$ret,'RETVAL');
2233 $db-&gt;Execute($stmt); </font></pre>
2235 <p>Note that the only difference between the oci8 and mssql implementations is $sql.</p>
2237 If $type parameter is set to false, in mssql, $type will be dynamicly determined
2238 based on the type of the PHP variable passed <font face="Courier New, Courier, mono">(string
2239 =&gt; SQLCHAR, boolean =&gt;SQLINT1, integer =&gt;SQLINT4 or float/double=&gt;SQLFLT8)</font>.
2240 <p>
2241 In oci8, $type can be set to OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File),
2242 OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID). To
2243 pass in a null, use<font face="Courier New, Courier, mono"> $db-&gt;Parameter($stmt,
2244 $null=null, 'param')</font>.
2245 <p><b> OutParameter<a name="outparameter"></a>($stmt, $var, $name,
2246 $maxLen = 4000, $type = false )</b></p>
2247 Binds a PHP variable as output from a stored procedure variable. The parameter <i>$stmt</i>
2248 is the value returned by PrepareSP(), <i>$var</i> is the PHP variable you want to bind, <i>$name</i>
2249 is the name of the stored procedure variable. Optional is <i>$maxLen</i>, the maximum length of the
2250 data to bind, and <i>$type</i> which is database dependant.
2252 OutParameter() is a wrapper function that calls Parameter() with $isOutput=true.
2253 The advantage of this function is that it is self-documenting, because
2254 the $isOutput parameter is no longer needed. Only for mssql
2255 and oci8 currently.
2257 For an example, see <a href=#inparameter>InParameter</a>.
2259 <p><b> Parameter<a name="parameter"></a>($stmt, $var, $name, $isOutput=false,
2260 $maxLen = 4000, $type = false )</b></p>
2261 <p>Note: This function is deprecated, because of the new InParameter() and OutParameter() functions.
2262 These are superior because they are self-documenting, unlike Parameter().
2263 <p>Adds a bind parameter suitable for return values or special data handling (eg.
2264 LOBs) after a statement has been prepared using PrepareSP(). Only for mssql
2265 and oci8 currently. The parameters are:<br>
2266 <br>
2267 $<i><b>stmt</b></i> Statement returned by Prepare() or PrepareSP().<br>
2268 $<i><b>var</b></i> PHP variable to bind to. Make sure you pre-initialize it!<br>
2269 $<i><b>name</b></i> Name of stored procedure variable name to bind to.<br>
2270 [$<i><b>isOutput</b></i>] Indicates direction of parameter 0/false=IN 1=OUT
2271 2= IN/OUT. This is ignored in oci8 as this driver auto-detects the direction.<br>
2272 [$<b>maxLen</b>] Maximum length of the parameter variable.<br>
2273 [$<b>type</b>] Consult <a href="http://php.net/mssql_bind">mssql_bind</a> and
2274 <a href="http://php.net/ocibindbyname">ocibindbyname</a> docs at php.net for
2275 more info on legal values for type.</p>
2276 <p>Lastly, in oci8, bind parameters can be reused without calling PrepareSP( )
2277 or Parameters again. This is not possible with mssql. An oci8 example:</p>
2278 <pre>$id = 0; $i = 0;
2279 $stmt = $db-&gt;PrepareSP( <font color="#993300">&quot;update table set val=:i where id=:id&quot;</font>);
2280 $db-&gt;Parameter($stmt,$id,'id');
2281 $db-&gt;Parameter($stmt,$i, 'i');
2282 for ($cnt=0; $cnt &lt; 1000; $cnt++) {
2283 $id = $cnt; <br> $i = $cnt * $cnt; <font color="green"># works with oci8!</font>
2284 $db-&gt;Execute($stmt); <br>}</pre>
2285 <p><b>Bind<a name="bind"></a>($stmt, $var, $size=4001, $type=false, $name=false)</b></p>
2286 </font>
2287 <p><font color="#000000">This is a low-level function supported only by the oci8
2288 driver. <b>Avoid using</b> unless you only want to support Oracle. The Parameter(
2289 ) function is the recommended way to go with bind variables.</font></p>
2290 <p><font color="#000000">Bind( ) allows you to use bind variables in your sql
2291 statement. This binds a PHP variable to a name defined in an Oracle sql statement
2292 that was previously prepared using Prepare(). Oracle named variables begin with
2293 a colon, and ADOdb requires the named variables be called :0, :1, :2, :3, etc.
2294 The first invocation of Bind() will match :0, the second invocation will match
2295 :1, etc. Binding can provide 100% speedups for insert, select and update statements.
2296 </font></p>
2297 <p>The other variables, $size sets the buffer size for data storage, $type is
2298 the optional descriptor type OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File),
2299 OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID).
2300 Lastly, instead of using the default :0, :1, etc names, you can define your
2301 own bind-name using $name.
2302 <p><font color="#000000">The following example shows 3 bind variables being used:
2303 p1, p2 and p3. These variables are bound to :0, :1 and :2.</font></p>
2304 <pre>$stmt = $DB-&gt;Prepare(&quot;insert into table (col0, col1, col2) values (:0, :1, :2)&quot;);
2305 $DB-&gt;Bind($stmt, $p1);
2306 $DB-&gt;Bind($stmt, $p2);
2307 $DB-&gt;Bind($stmt, $p3);
2308 for ($i = 0; $i &lt; $max; $i++) {
2309 $p1 = ?; $p2 = ?; $p3 = ?;
2310 $DB-&gt;Execute($stmt);
2311 }</pre>
2312 <p>You can also use named variables:</p>
2313 <pre>
2314 $stmt = $DB-&gt;Prepare(&quot;insert into table (col0, col1, col2) values (:name0, :name1, :name2)&quot;);
2315 $DB-&gt;Bind($stmt, $p1, &quot;name0&quot;);
2316 $DB-&gt;Bind($stmt, $p2, &quot;name1&quot;);
2317 $DB-&gt;Bind($stmt, $p3, &quot;name2&quot;);
2318 for ($i = 0; $i &lt; $max; $i++) {
2319 $p1 = ?; $p2 = ?; $p3 = ?;
2320 $DB-&gt;Execute($stmt);
2321 }</pre>
2322 <p><b>LogSQL($enable=true)<a name=logsql></a></b></p>
2323 Call this method to install a SQL logging and timing function (using fnExecute).
2324 Then all SQL statements are logged into an adodb_logsql table in a database. If
2325 the adodb_logsql table does not exist, ADOdb will create the table if you have
2326 the appropriate permissions. Returns the previous logging value (true for enabled,
2327 false for disabled). Here are samples of the DDL for selected databases:
2328 <p>
2329 <pre>
2330 <b>mysql:</b>
2331 CREATE TABLE adodb_logsql (
2332 created datetime NOT NULL,
2333 sql0 varchar(250) NOT NULL,
2334 sql1 text NOT NULL,
2335 params text NOT NULL,
2336 tracer text NOT NULL,
2337 timer decimal(16,6) NOT NULL
2340 <b>postgres:</b>
2341 CREATE TABLE adodb_logsql (
2342 created timestamp NOT NULL,
2343 sql0 varchar(250) NOT NULL,
2344 sql1 text NOT NULL,
2345 params text NOT NULL,
2346 tracer text NOT NULL,
2347 timer decimal(16,6) NOT NULL
2350 <b>mssql:</b>
2351 CREATE TABLE adodb_logsql (
2352 created datetime NOT NULL,
2353 sql0 varchar(250) NOT NULL,
2354 sql1 varchar(4000) NOT NULL,
2355 params varchar(3000) NOT NULL,
2356 tracer varchar(500) NOT NULL,
2357 timer decimal(16,6) NOT NULL
2360 <b>oci8:</b>
2361 CREATE TABLE adodb_logsql (
2362 created date NOT NULL,
2363 sql0 varchar(250) NOT NULL,
2364 sql1 varchar(4000) NOT NULL,
2365 params varchar(4000),
2366 tracer varchar(4000),
2367 timer decimal(16,6) NOT NULL
2369 </pre>
2370 Usage:
2371 <pre>
2372 $conn->LogSQL(); // turn on logging
2374 $conn->Execute(...);
2376 $conn->LogSQL(false); // turn off logging
2378 # output summary of SQL logging results
2379 $perf = NewPerfMonitor($conn);
2380 echo $perf->SuspiciousSQL();
2381 echo $perf->ExpensiveSQL();
2382 </pre>
2383 <p>One limitation of logging is that rollback also prevents SQL from being logged.
2385 If you prefer to use another name for the table used to store the SQL, you can override it by calling
2386 adodb_perf::table($tablename), where $tablename is the new table name (you will still need to manually
2387 create the table yourself). An example:
2388 <pre>
2389 include('adodb.inc.php');
2390 include('adodb-perf.inc.php');
2391 adodb_perf::table('my_logsql_table');
2392 </pre>
2393 Also see <a href=docs-perf.htm>Performance Monitor</a>.
2394 <p><font color="#000000"><b>fnExecute and fnCacheExecute properties<a name="fnexecute" id="fnexecute"></a></b></font></p>
2395 <p>These two properties allow you to define bottleneck functions for all sql statements
2396 processed by ADOdb. This allows you to perform statistical analysis and query-rewriting
2397 of your sql.
2398 <p><b>Examples of fnExecute</b></p>
2399 <p>Here is an example of using fnExecute, to count all cached queries and non-cached
2400 queries, you can do this:</p>
2401 <pre><font color="#006600"># $db is the connection object</font>
2402 function CountExecs($db, $sql, $inputarray)
2404 global $EXECS;
2406 if (!is_array(inputarray)) $EXECS++;
2407 <font color="#006600"># handle 2-dimensional input arrays</font>
2408 else if (is_array(reset($inputarray))) $EXECS += sizeof($inputarray);
2409 else $EXECS++;
2412 <font color="#006600"># $db is the connection object</font>
2413 function CountCachedExecs($db, $secs2cache, $sql, $inputarray)
2414 {<br>global $CACHED; $CACHED++;
2416 <br>$db = NewADOConnection('mysql');
2417 $db-&gt;Connect(...);
2418 $db-&gt;<strong>fnExecute</strong> = 'CountExecs';
2419 $db-&gt;<strong>fnCacheExecute</strong> = 'CountCachedExecs';
2421 :<br><font color="#006600"># After many sql statements:</font>`
2422 printf(&quot;&lt;p&gt;Total queries=%d; total cached=%d&lt;/p&gt;&quot;,$EXECS+$CACHED, $CACHED);
2423 </pre>
2424 <p>The fnExecute function is called before the sql is parsed and executed, so
2425 you can perform a query rewrite. If you are passing in a prepared statement,
2426 then $sql is an array (see <a href="#prepare">Prepare</a>). The fnCacheExecute
2427 function is only called if the recordset returned was cached.<font color="#000000">
2428 The function parameters match the Execute and CacheExecute functions respectively,
2429 except that $this (the connection object) is passed as the first parameter.</font></p>
2430 <p>Since ADOdb 3.91, the behaviour of fnExecute varies depending on whether the
2431 defined function returns a value. If it does not return a value, then the $sql
2432 is executed as before. This is useful for query rewriting or counting sql queries.
2433 <p> On the other hand, you might want to replace the Execute function with one
2434 of your own design. If this is the case, then have your function return a value.
2435 If a value is returned, that value is returned immediately, without any further
2436 processing. This is used internally by ADOdb to implement LogSQL() functionality.
2437 <p> <font color="#000000">
2438 <hr>
2439 <h3>ADOConnection Utility Functions</h3>
2440 <p><b>BlankRecordSet<a name="blankrecordset"></a>([$queryid])</b></p>
2441 <p>No longer available - removed since 1.99.</p>
2442 <p><b>Concat<a name="concat"></a>($s1,$s2,....)</b></p>
2443 <p>Generates the sql string used to concatenate $s1, $s2, etc together. Uses the
2444 string in the concat_operator field to generate the concatenation. Override
2445 this function if a concatenation operator is not used, eg. MySQL.</p>
2446 <p>Returns the concatenated string.</p>
2447 <p><b>DBDate<a name="dbdate"></a>($date)</b></p>
2448 <p>Format the $<b>date</b> in the format the database accepts. This is used in
2449 INSERT/UPDATE statements; for SELECT statements, use <a href="#sqldate">SQLDate</a>.
2450 The $<b>date</b> parameter can be a Unix integer timestamp or an ISO format
2451 Y-m-d. Uses the fmtDate field, which holds the format to use. If null or false
2452 or '' is passed in, it will be converted to an SQL null.</p>
2453 <p>Returns the date as a quoted string.</p>
2454 <p><b>DBTimeStamp<a name="dbtimestamp"></a>($ts)</b></p>
2455 <p>Format the timestamp $<b>ts</b> in the format the database accepts; this can
2456 be a Unix integer timestamp or an ISO format Y-m-d H:i:s. Uses the fmtTimeStamp
2457 field, which holds the format to use. If null or false or '' is passed in, it
2458 will be converted to an SQL null.</p>
2459 <p>Returns the timestamp as a quoted string.</p>
2460 <p><b>qstr<a name="qstr"></a>($s,[$magic_quotes_enabled</b>=false]<b>)</b></p>
2461 <p>Quotes a string to be sent to the database. The $<b>magic_quotes_enabled</b>
2462 parameter may look funny, but the idea is if you are quoting a string extracted
2463 from a POST/GET variable, then pass get_magic_quotes_gpc() as the second parameter.
2464 This will ensure that the variable is not quoted twice, once by <i>qstr</i>
2465 and once by the <i>magic_quotes_gpc</i>.</p>
2466 <p>Eg.<font face="Courier New, Courier, mono"> $s = $db-&gt;qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());</font></p>
2467 <p>Returns the quoted string.</p>
2468 <p><b>Quote<a name="quote"></a>($s)</b></p>
2469 <p>Quotes the string $s, escaping the database specific quote character as appropriate.
2470 Formerly checked magic quotes setting, but this was disabled since 3.31 for
2471 compatibility with PEAR DB.
2472 <p><b>Affected_Rows<a name="affected_rows"></a>( )</b></p>
2473 <p>Returns the number of rows affected by a update or delete statement. Returns
2474 false if function not supported.</p>
2475 <p>Not supported by interbase/firebird currently. </p>
2476 <p><b>Insert_ID<a name="inserted_id"></a>( )</b></p>
2477 <p>Returns the last autonumbering ID inserted. Returns false if function not supported.
2478 </p>
2479 <p>Only supported by databases that support auto-increment or object id's, such
2480 as PostgreSQL, MySQL and MS SQL Server currently. PostgreSQL returns the OID, which
2481 can change on a database reload.</p>
2482 <p><b>RowLock<a name="rowlock"></a>($table,$where)</b></p>
2483 <p>Lock a table row for the duration of a transaction. For example to lock record $id in table1:
2484 <pre>
2485 $DB->StartTrans();
2486 $DB->RowLock("table1","rowid=$id");
2487 $DB->Execute($sql1);
2488 $DB->Execute($sql2);
2489 $DB->CompleteTrans();
2490 </pre>
2491 <p>Supported in db2, interbase, informix, mssql, oci8, postgres, sybase.
2492 <p><b>MetaDatabases<a name="metadatabases"></a>()</b></p>
2493 <p>Returns a list of databases available on the server as an array. You have to
2494 connect to the server first. Only available for ODBC, MySQL and ADO.</p>
2495 <p><b>MetaTables<a name="metatables"></a>($ttype = false, $showSchema = false,
2496 $mask=false)</b></p>
2497 <p>Returns an array of tables and views for the current database as an array.
2498 The array should exclude system catalog tables if possible. To only show tables,
2499 use $db->MetaTables('TABLES'). To show only views, use $db->MetaTables('VIEWS').
2500 The $showSchema parameter currently works only for DB2, and when set to true,
2501 will add the schema name to the table, eg. "SCHEMA.TABLE". </p>
2502 <p>You can define a mask for matching. For example, setting $mask = 'TMP%' will
2503 match all tables that begin with 'TMP'. Currently only mssql, oci8, odbc_mssql
2504 and postgres* support $mask.
2505 <p><b>MetaColumns<a name="metacolumns"></a>($table,$toupper=true)</b></p>
2506 <p>Returns an array of ADOFieldObject's, one field object for every column of
2507 $table. A field object is a class instance with (name, type, max_length) defined.
2508 Currently Sybase does not recognise date types, and ADO cannot identify
2509 the correct data type (so we default to varchar).
2510 <p> The $toupper parameter determines whether we uppercase the table name
2511 (required for some databases).
2512 <p>For schema support, pass in the $table parameter, "$schema.$tablename". This is only
2513 supported for selected databases.
2514 <p><b>MetaColumnNames<a name="metacolumnames"></a>($table)</b></p>
2515 <p>Returns an array of column names for $table.
2516 <p><font color="#000000"><b>MetaPrimaryKeys<a name="metaprimarykeys"></a>($table,
2517 $owner=false)</b></font></font>
2518 <p><font color="#000000">Returns an array containing column names that are the
2519 primary keys of $table. Supported by mysql, odbc (including db2, odbc_mssql,
2520 etc), mssql, postgres, interbase/firebird, oci8 currently. </font><font color="#000000">
2521 <p>Views (and some tables) have primary keys, but sometimes this information is not available from the
2522 database. You can define a function ADODB_View_PrimaryKeys($databaseType, $database, $view, $owner) that
2523 should return an array containing the fields that make up the primary key. If that function exists,
2524 it will be called when MetaPrimaryKeys() cannot find a primary key for a table or view.
2525 <pre>
2526 // In this example: dbtype = 'oci8', $db = 'mydb', $view = 'dataView', $owner = false
2527 function ADODB_View_PrimaryKeys($dbtype,$db,$view,$owner)
2529 switch(strtoupper($view)) {
2530 case 'DATAVIEW': return array('DATAID');
2531 default: return false;
2535 $db = NewADOConnection('oci8');
2536 $db->Connect('localhost','root','','mydb');
2537 $db->MetaPrimaryKeys('dataView');
2538 </pre>
2539 <p><font color="#000000"><b>ServerInfo<a name="serverinfo" id="serverinfo"></a>($table)</b></font></font>
2540 <p><font color="#000000">Returns an array of containing two elements 'description'
2541 and 'version'. The 'description' element contains the string description of
2542 the database. The 'version' naturally holds the version number (which is also
2543 a string).</font><font color="#000000">
2544 <p><b>MetaForeignKeys<a name="metaforeignkeys"></a>($table, $owner=false, $upper=false)</b>
2545 <p>Returns an associate array of foreign keys, or false if not supported. For
2546 example, if table employee has a foreign key where employee.deptkey points to
2547 dept_table.deptid, and employee.posn=posn_table.postionid and employee.poscategory=posn_table.category,
2548 then $conn->MetaForeignKeys('employee') will return
2549 <pre>
2550 array(
2551 'dept_table' => array('deptkey=deptid'),
2552 'posn_table' => array('posn=positionid','poscategory=category')
2554 </pre>
2555 <p>The optional schema or owner can be defined in $owner. If $upper is true, then
2556 the table names (array keys) are upper-cased.
2557 <hr>
2558 <h2>ADORecordSet<a name="adorecordset"></a></h2>
2559 <p>When an SQL statement successfully is executed by <font face="Courier New, Courier, mono">ADOConnection-&gt;Execute($sql),</font>an
2560 ADORecordSet object is returned. This object contains a virtual cursor so we
2561 can move from row to row, functions to obtain information about the columns
2562 and column types, and helper functions to deal with formating the results to
2563 show to the user.</p>
2564 <h3>ADORecordSet Fields</h3>
2565 <p><b>fields: </b>Array containing the current row. This is not associative, but
2566 is an indexed array from 0 to columns-1. See also the function <b><a href="#fields">Fields</a></b>,
2567 which behaves like an associative array.</p>
2568 <p><b>dataProvider</b>: The underlying mechanism used to connect to the database.
2569 Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</p>
2570 <p><b>blobSize</b>: Maximum size of a char, string or varchar object before it
2571 is treated as a Blob (Blob's should be shown with textarea's). See the <a href="#metatype">MetaType</a>
2572 function.</p>
2573 <p><b>sql</b>: Holds the sql statement used to generate this record set.</p>
2574 <p><b>canSeek</b>: Set to true if Move( ) function works.</p>
2575 <p><b>EOF</b>: True if we have scrolled the cursor past the last record.</p>
2576 <h3>ADORecordSet Functions</h3>
2577 <p><b>ADORecordSet( )</b></p>
2578 <p>Constructer. Normally you never call this function yourself.</p>
2579 <p><b>GetAssoc<a name="getassoc"></a>([$force_array])</b></p>
2580 <p>Generates an associative array from the recordset. Note that is this function
2581 is also <a href="#getassoc1">available</a> in the connection object. More details
2582 can be found there.</p>
2583 </font></font><font color="#000000"><font color="#000000"> </font></font><font color="#000000"><font color="#000000">
2584 <p><b>GetArray<a name="getarray"></a>([$number_of_rows])</b></p>
2585 <p>Generate a 2-dimensional array of records from the current cursor position,
2586 indexed from 0 to $number_of_rows - 1. If $number_of_rows is undefined, till
2587 EOF.</p>
2588 <p><b>GetRows<a name="getrows"></a>([$number_of_rows])</b></p>
2589 Generate a 2-dimensional array of records from the current cursor position. Synonym
2590 for GetArray() for compatibility with Microsoft ADO.
2591 <p> <b>GetMenu<a name="getmenu"></a>($name, [$default_str=''], [$blank1stItem=true],
2592 [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>
2593 <p>Generate a HTML menu (&lt;select&gt;&lt;option&gt;&lt;option&gt;&lt;/select&gt;).
2594 The first column of the recordset (fields[0]) will hold the string to display
2595 in the option tags. If the recordset has more than 1 column, the second column
2596 (fields[1]) is the value to send back to the web server.. The menu will be given
2597 the name $<i>name</i>.
2598 <p> If $<i>default_str</i> is defined, then if $<i>default_str</i> == fields[0],
2599 that field is selected. If $<i>blank1stItem</i> is true, the first option is
2600 empty. You can also set the first option strings by setting $blank1stItem =
2601 "$value:$text".</p>
2602 <p>$<i>Default_str</i> can be array for a multiple select listbox.</p>
2603 <p>To get a listbox, set the $<i>size</i> to a non-zero value (or pass $default_str
2604 as an array). If $<i>multiple_select</i> is true then a listbox will be generated
2605 with $<i>size</i> items (or if $size==0, then 5 items) visible, and we will
2606 return an array to a server. Lastly use $<i>moreAttr </i> to add additional
2607 attributes such as javascript or styles. </p>
2608 <p>Menu Example 1: <code>GetMenu('menu1','A',true)</code> will generate a menu:
2609 <select name='menu1'>
2610 <option>
2611 <option value=1 selected>A
2612 <option value=2>B
2613 <option value=3>C
2614 </select>
2615 for the data (A,1), (B,2), (C,3). Also see <a href="#ex5">example 5</a>.</p>
2616 <p>Menu Example 2: For the same data, <code>GetMenu('menu1',array('A','B'),false)</code>
2617 will generate a menu with both A and B selected: <br>
2618 <select name='menu1' multiple size=3>
2619 <option value=1 selected>A
2620 <option value=2 selected>B
2621 <option value=3>C
2622 </select>
2623 <p> <b>GetMenu2<a name="getmenu2"></a>($name, [$default_str=''], [$blank1stItem=true],
2624 [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>
2625 <p>This is nearly identical to GetMenu, except that the $<i>default_str</i> is
2626 matched to fields[1] (the option values).</p>
2627 <p>Menu Example 3: Given the data in menu example 2, <code>GetMenu2('menu1',array('1','2'),false)</code>
2628 will generate a menu with both A and B selected in menu example 2, but this
2629 time the selection is based on the 2nd column, which holds the values to return
2630 to the Web server.
2631 <p><b>UserDate<a name="userdate"></a>($str, [$fmt])</b></p>
2632 <p>Converts the date string $<i>str</i> to another format. The date format is Y-m-d,
2633 or Unix timestamp format. The default $<i>fmt</i> is Y-m-d.</p>
2634 <p><b>UserTimeStamp<a name="usertimestamp"></a>($str, [$fmt])</b></p>
2635 <p>Converts the timestamp string $<b>str</b> to another format. The timestamp
2636 format is Y-m-d H:i:s, as in '2002-02-28 23:00:12', or Unix timestamp format.
2637 UserTimeStamp calls UnixTimeStamp to parse $<i>str</i>, and $<i>fmt</i> defaults to Y-m-d H:i:s if not defined.
2638 </p>
2639 <p><b>UnixDate<a name="unixdate"></a>($str)</b></p>
2640 <p>Parses the date string $<b>str</b> and returns it in unix mktime format (eg.
2641 a number indicating the seconds after January 1st, 1970). Expects the date to
2642 be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, where
2643 M d Y is also accepted (the 3 letter month strings are controlled by a global
2644 array, which might need localisation).</p>
2645 <p>This function is available in both ADORecordSet and ADOConnection since 1.91.</p>
2646 <p><b>UnixTimeStamp<a name="unixtimestamp"></a>($str)</b></p>
2647 <p>Parses the timestamp string $<b>str</b> and returns it in unix mktime format
2648 (eg. a number indicating the seconds after January 1st, 1970). Expects the date
2649 to be in "Y-m-d, H:i:s" (1970-12-24, 00:00:00) or "Y-m-d H:i:s" (1970-12-24 00:00:00) or "YmdHis" (19701225000000) format, except for Sybase and Microsoft SQL Server, where
2650 "M d Y h:i:sA" (Dec 25 1970 00:00:00AM) is also accepted (the 3 letter month strings are controlled by
2651 a global array, which might need localisation).</p>
2652 </font>
2653 <p><font color="#000000">This function is available in both ADORecordSet and ADOConnection
2654 since 1.91. </font></p>
2655 <p><font color="#000000"><b>OffsetDate<a name="offsetdate"></a>($dayFraction,
2656 $basedate=false)</b></font></p>
2657 <p><font color="#000000"><font color="#000000">Returns a string </font>with the
2658 native SQL functions to calculate future and past dates based on $basedate in
2659 a portable fashion. If $basedate is not defined, then the current date (at 12
2660 midnight) is used. Returns the SQL string that performs the calculation when
2661 passed to Execute(). </font></p>
2662 <p><font color="#000000">For example, in Oracle, to find the date and time that
2663 is 2.5 days from today, you can use:</font></p>
2664 <pre><font color="#000000"># get date one week from now
2665 $fld = $conn-&gt;OffsetDate(7); // returns &quot;(trunc(sysdate)+7&quot;)</font></pre>
2666 <pre><font color="#000000"># get date and time that is 60 hours from current date and time
2667 $fld = $conn-&gt;OffsetDate(2.5, $conn-&gt;sysTimeStamp); // returns &quot;(sysdate+2.5)&quot;</font>
2669 $conn-&gt;Execute(&quot;UPDATE TABLE SET dodate=$fld WHERE ID=$id&quot;);</pre>
2670 <p> This function is available for mysql, mssql, oracle, oci8 and postgresql drivers
2671 since 2.13. It might work with other drivers<font color="#000000"> provided
2672 they allow performing numeric day arithmetic on dates.</font></p>
2673 <font color="#000000">
2674 <p><font color="#000000"><b>SQLDate<a name="sqldate"></a>($dateFormat, $basedate=false)</b></font></p>
2675 Returns a string which contains the native SQL functions to format a date or date
2676 column $basedate. This is used in SELECT statements. For INSERT/UPDATE statements,
2677 use <a href="#dbdate">DBDate</a>. It uses a case-sensitive $dateFormat, which
2678 supports:
2679 <pre>
2680 Y: 4-digit Year
2681 Q: Quarter (1-4)
2682 m: Month (01-12)
2683 d: Day (01-31)
2684 H: Hour (00-23)
2685 h: Hour (1-12)
2686 i: Minute (00-59)
2687 s: Second (00-60)
2688 A: AM/PM indicator</pre>
2689 <p>All other characters are treated as strings. You can also use \ to escape characters.
2690 Available on selected databases, including mysql, postgresql, mssql, oci8 and
2691 DB2.
2692 <p>This is useful in writing portable sql statements that GROUP BY on dates. For
2693 example to display total cost of goods sold broken by quarter (dates are stored
2694 in a field called postdate):
2695 <pre>
2696 $sqlfn = $db->SQLDate('Y-\QQ','postdate'); # get sql that formats postdate to output 2002-Q1
2697 $sql = "SELECT $sqlfn,SUM(cogs) FROM table GROUP BY $sqlfn ORDER BY 1 desc";
2698 </pre>
2699 <p><b>MoveNext<a name="movenext"></a>( )</b></p>
2700 <p>Move the internal cursor to the next row. The <i>$this->fields</i> array is
2701 automatically updated. Returns false if unable to do so (normally because EOF
2702 has been reached), otherwise true.
2703 <p> If EOF is reached, then the $this->fields array is set to false (this was
2704 only implemented consistently in ADOdb 3.30). For the pre-3.30 behaviour of
2705 $this->fields (at EOF), set the global variable $ADODB_COMPAT_FETCH = true.</p>
2706 <p>Example:</p>
2707 <pre>$rs = $db-&gt;Execute($sql);
2708 if ($rs)
2709 while (!$rs-&gt;EOF) {
2710 ProcessArray($rs->fields);
2711 $rs->MoveNext();
2712 } </pre>
2713 <p><b>Move<a name="move"></a>($to)</b></p>
2714 <p>Moves the internal cursor to a specific row $<b>to</b>. Rows are zero-based
2715 eg. 0 is the first row. The <b>fields</b> array is automatically updated. For
2716 databases that do not support scrolling internally, ADOdb will simulate forward
2717 scrolling. Some databases do not support backward scrolling. If the $<b>to</b>
2718 position is after the EOF, $<b>to</b> will move to the end of the RecordSet
2719 for most databases. Some obscure databases using odbc might not behave this
2720 way.</p>
2721 <p>Note: This function uses <i>absolute positioning</i>, unlike Microsoft's ADO.</p>
2722 <p>Returns true or false. If false, the internal cursor is not moved in most implementations,
2723 so AbsolutePosition( ) will return the last cursor position before the Move(
2724 ). </p>
2725 <p><b>MoveFirst<a name="movefirst"></a>()</b></p>
2726 <p>Internally calls Move(0). Note that some databases do not support this function.</p>
2727 <p><b>MoveLast<a name="movelast"></a>()</b></p>
2728 <p>Internally calls Move(RecordCount()-1). Note that some databases do not support
2729 this function.</p>
2730 <p><b>GetRowAssoc</b><a name="getrowassoc"></a>($toUpper=true)</p>
2731 <p>Returns an associative array containing the current row. The keys to the array
2732 are the column names. The column names are upper-cased for easy access. To get
2733 the next row, you will still need to call MoveNext(). </p>
2734 <p>For example:<br>
2735 Array ( [ID] => 1 [FIRSTNAME] => Caroline [LASTNAME] => Miranda [CREATED] =>
2736 2001-07-05 ) </p>
2737 <p>Note: do not use GetRowAssoc() with $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC.
2738 Because they have the same functionality, they will interfere with each other.</p>
2739 </font>
2740 <p><font color="#000000"><b>AbsolutePage<a name="absolutepage"></a>($page=-1)
2741 </b></font></p>
2742 <p>Returns the current page. Requires PageExecute()/CachePageExecute() to be called.
2743 See <a href=#ex8>Example 8</a>.</p>
2744 <font color="#000000">
2745 <p><b>AtFirstPage<a name="atfirstpage">($status='')</a></b></p>
2746 <p>Returns true if at first page (1-based). Requires PageExecute()/CachePageExecute()
2747 to be called. See <a href=#ex8>Example 8</a>.</p>
2748 <p><b>AtLastPage<a name="atlastpage">($status='')</a></b></p>
2749 <p>Returns true if at last page (1-based). Requires PageExecute()/CachePageExecute()
2750 to be called. See <a href=#ex8>Example 8</a>.</p>
2751 <p><b>Fields</b><a name="fields"></a>(<b>$colname</b>)</p>
2752 <p>Returns the value of the
2753 associated column $<b>colname</b> for the current row. The column name is case-insensitive.</p>
2754 <p>This is a convenience function. For higher performance, use <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>. </p>
2755 <p><b>FetchRow</b><a name="fetchrow"></a>()</p>
2756 </font>
2757 <p><font color="#000000">Returns array containing current row, or false if EOF.
2758 FetchRow( ) internally moves to the next record after returning the current
2759 row. </font></p>
2760 <p><font color="#000000">Warning: Do not mix using FetchRow() with MoveNext().</font></p>
2761 <p><font color="#000000">Usage:</font></p>
2762 <pre><font color="#000000">$rs = $db-&gt;Execute($sql);
2763 if ($rs)
2764 while ($arr = $rs-&gt;FetchRow()) &#123;
2765 &nbsp;&nbsp;# process $arr
2766 </font><font color="#000000"> &#125;</font></pre>
2767 <p><font color="#000000"><b>FetchInto</b><a name="fetchinto"></a>(<b>&amp;$array</b>)</font></p>
2768 <p><font color="#000000"> Sets $array to the current row. Returns PEAR_Error object
2769 if EOF, 1 if ok (DB_OK constant). If PEAR is undefined, false is returned when
2770 EOF. </font><font color="#000000">FetchInto( ) internally moves to the next
2771 record after returning the current row. </font></p>
2772 <p><font color="#000000"> FetchRow() is easier to use. See above.</font></p>
2773 <font color="#000000">
2774 <p><b>FetchField<a name="fetchfield"></a>($column_number)</b></p>
2775 <p>Returns an object containing the <b>name</b>, <b>type</b> and <b>max_length</b>
2776 of the associated field. If the max_length cannot be determined reliably, it
2777 will be set to -1. The column numbers are zero-based. See <a href="#ex2">example
2778 2.</a></p>
2779 <p><b>FieldCount<a name="fieldcount"></a>( )</b></p>
2780 <p>Returns the number of fields (columns) in the record set.</p>
2781 <p><b>RecordCount<a name="recordcount"></a>( )</b></p>
2782 <p>Returns the number of rows in the record set. If the number of records returned
2783 cannot be determined from the database driver API, we will buffer all rows and
2784 return a count of the rows after all the records have been retrieved. This buffering
2785 can be disabled (for performance reasons) by setting the global variable $ADODB_COUNTRECS
2786 = false. When disabled, RecordCount( ) will return -1 for certain databases.
2787 See the supported databases list above for more details. </p>
2788 <p> RowCount is a synonym for RecordCount.</p>
2789 <p><b>PO_RecordCount<a name="po_recordcount"></a>($table, $where)</b></p>
2790 <p>Returns the number of rows in the record set. If the database does not support
2791 this, it will perform a SELECT COUNT(*) on the table $table, with the given
2792 $where condition to return an estimate of the recordset size.</p>
2793 <p>$numrows = $rs-&gt;PO_RecordCount(&quot;articles_table&quot;, &quot;group=$group&quot;);</p>
2794 <b> NextRecordSet<a name="nextrecordset" id="nextrecordset"></a>()</b>
2795 <p>For databases that allow multiple recordsets to be returned in one query, this
2796 function allows you to switch to the next recordset. Currently only supported
2797 by mssql driver.</p>
2798 <pre>
2799 $rs = $db-&gt;Execute('execute return_multiple_rs');
2800 $arr1 = $rs-&gt;GetArray();
2801 $rs-&gt;NextRecordSet();
2802 $arr2 = $rs-&gt;GetArray();</pre>
2803 <p><b>FetchObject<a name="fetchobject"></a>($toupper=true)</b></p>
2804 <p>Returns the current row as an object. If you set $toupper to true, then the
2805 object fields are set to upper-case. Note: The newer FetchNextObject() is the
2806 recommended way of accessing rows as objects. See below.</p>
2807 <p><b>FetchNextObject<a name="fetchnextobject"></a>($toupper=true)</b></p>
2808 <p>Gets the current row as an object and moves to the next row automatically.
2809 Returns false if at end-of-file. If you set $toupper to true, then the object
2810 fields are set to upper-case.</p>
2811 <pre>
2812 $rs = $db->Execute('select firstname,lastname from table');
2813 if ($rs) &#123;
2814 while ($o = $rs->FetchNextObject()) &#123;
2815 print "$o->FIRSTNAME, $o->LASTNAME&lt;BR>";
2816 &#125;
2817 &#125;
2818 </pre>
2819 <p>There is some trade-off in speed in using FetchNextObject(). If performance
2820 is important, you should access rows with the <code>fields[]</code> array. <b>FetchObj<a name="fetchobj" id="fetchobj"></a>()</b>
2821 <p>Returns the current record as an object. Fields are not upper-cased, unlike
2822 FetchObject. </font>
2823 <p><font color="#000000"><b>FetchNextObj<a name="fetchnextobj" id="fetchnextobj"></a>()</b>
2824 </font></p>
2825 <p><font color="#000000">Returns the current record as an object and moves to
2826 the next record. If EOF, false is returned. Fields are not upper-cased, unlike
2827 FetctNextObject. </font></p>
2828 <font color="#000000">
2829 <p><b>CurrentRow<a name="currentrow"></a>( )</b></p>
2830 <p>Returns the current row of the record set. 0 is the first row.</p>
2831 <p><b>AbsolutePosition<a name="abspos"></a>( )</b></p>
2832 <p>Synonym for <b>CurrentRow</b> for compatibility with ADO. Returns the current
2833 row of the record set. 0 is the first row.</p>
2834 <p><b>MetaType<a name="metatype"></a>($nativeDBType[,$field_max_length],[$fieldobj])</b></p>
2835 <p>Determine what <i>generic</i> meta type a database field type is given its
2836 native type $<b>nativeDBType</b> as a string and the length of the field $<b>field_max_length</b>.
2837 Note that field_max_length can be -1 if it is not known. The field object returned
2838 by FetchField() can be passed in $<b>fieldobj</b> or as the 1st parameter <b>$nativeDBType</b>.
2839 This is useful for databases such as <i>mysql</i> which has additional properties
2840 in the field object such as <i>primary_key</i>. </p>
2841 <p>Uses the field <b>blobSize</b> and compares it with $<b>field_max_length</b>
2842 to determine whether the character field is actually a blob.</p>
2843 For example, $db-&gt;MetaType('char') will return 'C'.
2844 <p>Returns:</p>
2845 <ul>
2846 <li><b>C</b>: Character fields that should be shown in a &lt;input type=&quot;text&quot;&gt;
2847 tag. </li>
2848 <li><b>X</b>: Clob (character large objects), or large text fields that should
2849 be shown in a &lt;textarea&gt;</li>
2850 <li><b>D</b>: Date field</li>
2851 <li><b>T</b>: Timestamp field</li>
2852 <li><b>L</b>: Logical field (boolean or bit-field)</li>
2853 <li><b>N</b>: Numeric field. Includes decimal, numeric, floating point, and
2854 real. </li>
2855 <li><b>I</b>:&nbsp; Integer field. </li>
2856 <li><b>R</b>: Counter or Autoincrement field. Must be numeric.</li>
2857 <li><b>B</b>: Blob, or binary large objects.<font color="#000000"> </font></li>
2858 </ul>
2859 </font>
2860 <p><font color="#000000"> Since ADOdb 3.0, MetaType accepts $fieldobj as the first
2861 parameter, instead of $nativeDBType. </font></p>
2862 <font color="#000000">
2863 <p><b>Close( )<a name="rsclose"></a></b></p>
2864 <p>Closes the recordset, cleaning all memory and resources associated with the recordset.
2866 If memory management is not an issue, you do not need to call this function as recordsets
2867 are closed for you by PHP at the end of the script.
2868 SQL statements such as INSERT/UPDATE/DELETE do not really return a recordset, so you do not have to call Close()
2869 for such SQL statements.</p>
2870 <hr>
2871 <h3>function rs2html<a name="rs2html"></a>($adorecordset,[$tableheader_attributes],
2872 [$col_titles])</h3>
2873 <p>This is a standalone function (rs2html = recordset to html) that is similar
2874 to PHP's <i>odbc_result_all</i> function, it prints a ADORecordSet, $<b>adorecordset</b>
2875 as a HTML table. $<b>tableheader_attributes</b> allow you to control the table
2876 <i>cellpadding</i>, <i>cellspacing</i> and <i>border</i> attributes. Lastly
2877 you can replace the database column names with your own column titles with the
2878 array $<b>col_titles</b>. This is designed more as a quick debugging mechanism,
2879 not a production table recordset viewer.</p>
2880 <p>You will need to include the file <i>tohtml.inc.php</i>.</p>
2881 <p>Example of rs2html:<b><font color="#336600"><a name="exrs2html"></a></font></b></p>
2882 <pre><b><font color="#336600">&lt;?
2883 include('tohtml.inc.php')</font></b>; # load code common to ADOdb
2884 <b>include</b>('adodb.inc.php'); # load code common to ADOdb
2885 $<font color="#663300">conn</font> = &amp;ADONewConnection('mysql'); # create a connection
2886 $<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db
2887 $<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';
2888 $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute($sql);
2889 <font color="#336600"><b>rs2html</b></font><b>($<font color="#663300">rs</font>,'<i>border=2 cellpadding=3</i>',array('<i>Customer Name','Customer ID</i>'));
2890 ?&gt;</b></pre>
2891 <hr>
2892 <h3>Differences between this ADOdb library and Microsoft ADO<a name="adodiff"></a></h3>
2893 <ol>
2894 <li>ADOdb only supports recordsets created by a connection object. Recordsets
2895 cannot be created independently.</li>
2896 <li>ADO properties are implemented as functions in ADOdb. This makes it easier
2897 to implement any enhanced ADO functionality in the future.</li>
2898 <li>ADOdb's <font face="Courier New, Courier, mono">ADORecordSet-&gt;Move()</font>
2899 uses absolute positioning, not relative. Bookmarks are not supported.</li>
2900 <li><font face="Courier New, Courier, mono">ADORecordSet-&gt;AbsolutePosition()
2901 </font>cannot be used to move the record cursor.</li>
2902 <li>ADO Parameter objects are not supported. Instead we have the ADOConnection::<a href="#parameter">Parameter</a>(
2903 ) function, which provides a simpler interface for calling preparing parameters
2904 and calling stored procedures.</li>
2905 <li>Recordset properties for paging records are available, but implemented as
2906 in <a href=#ex8>Example 8</a>.</li>
2907 </ol>
2908 <hr>
2909 <h1>Database Driver Guide<a name="driverguide"></a></h1>
2910 <p>This describes how to create a class to connect to a new database. To ensure
2911 there is no duplication of work, kindly email me at jlim#natsoft.com.my if you
2912 decide to create such a class.</p>
2913 <p>First decide on a name in lower case to call the database type. Let's say we
2914 call it xbase. </p>
2915 <p>Then we need to create two classes ADODB_xbase and ADORecordSet_xbase in the
2916 file adodb-xbase.inc.php.</p>
2917 <p>The simplest form of database driver is an adaptation of an existing ODBC driver.
2918 Then we just need to create the class <i>ADODB_xbase extends ADODB_odbc</i>
2919 to support the new <b>date</b> and <b>timestamp</b> formats, the <b>concatenation</b>
2920 operator used, <b>true</b> and <b>false</b>. For the<i> ADORecordSet_xbase extends
2921 ADORecordSet_odbc </i>we need to change the <b>MetaType</b> function. See<b>
2922 adodb-vfp.inc.php</b> as an example.</p>
2923 <p>More complicated is a totally new database driver that connects to a new PHP
2924 extension. Then you will need to implement several functions. Fortunately, you
2925 do not have to modify most of the complex code. You only need to override a
2926 few stub functions. See <b>adodb-mysql.inc.php</b> for example.</p>
2927 <p>The default date format of ADOdb internally is YYYY-MM-DD (Ansi-92). All dates
2928 should be converted to that format when passing to an ADOdb date function. See
2929 Oracle for an example how we use ALTER SESSION to change the default date format
2930 in _pconnect _connect.</p>
2931 <p><b>ADOConnection Functions to Override</b></p>
2932 <p>Defining a constructor for your ADOConnection derived function is optional.
2933 There is no need to call the base class constructor.</p>
2934 <p>_<b>connect</b>: Low level implementation of Connect. Returns true or false.
2935 Should set the _<b>connectionID</b>.</p>
2936 <p>_<b>pconnect:</b> Low level implemention of PConnect. Returns true or false.
2937 Should set the _<b>connectionID</b>.</p>
2938 <p>_<b>query</b>: Execute a query. Returns the queryID, or false.</p>
2939 <p>_<b>close: </b>Close the connection -- PHP should clean up all recordsets.
2940 </p>
2941 <p><b>ErrorMsg</b>: Stores the error message in the private variable _errorMsg.
2942 </p>
2943 <p><b>ADOConnection Fields to Set</b></p>
2944 <p>_<b>bindInputArray</b>: Set to true if binding of parameters for SQL inserts
2945 and updates is allowed using ?, eg. as with ODBC.</p>
2946 <p><b>fmtDate</b></p>
2947 <p><b>fmtTimeStamp</b></p>
2948 <p><b>true</b></p>
2949 <p><b>false</b></p>
2950 <p><b>concat_operator</b></p>
2951 <p><b>replaceQuote</b></p>
2952 <p><b>hasLimit</b> support SELECT * FROM TABLE LIMIT 10 of MySQL.</p>
2953 <p><b>hasTop</b> support Microsoft style SELECT TOP 10 * FROM TABLE.</p>
2954 <p><b>ADORecordSet Functions to Override</b></p>
2955 <p>You will need to define a constructor for your ADORecordSet derived class that
2956 calls the parent class constructor.</p>
2957 <p><b>FetchField: </b> as documented above in ADORecordSet</p>
2958 <p>_<b>initrs</b>: low level initialization of the recordset: setup the _<b>numOfRows</b>
2959 and _<b>numOfFields</b> fields -- called by the constructor.</p>
2960 <p>_<b>seek</b>: seek to a particular row. Do not load the data into the fields
2961 array. This is done by _fetch. Returns true or false. Note that some implementations
2962 such as Interbase do not support seek. Set canSeek to false.</p>
2963 <p>_<b>fetch</b>: fetch a row using the database extension function and then move
2964 to the next row. Sets the <b>fields</b> array. If the parameter $ignore_fields
2965 is true then there is no need to populate the <b>fields</b> array, just move
2966 to the next row. then Returns true or false.</p>
2967 <p>_<b>close</b>: close the recordset</p>
2968 <p><b>Fields</b>: If the array row returned by the PHP extension is not an associative
2969 one, you will have to override this. See adodb-odbc.inc.php for an example.
2970 For databases such as MySQL and MSSQL where an associative array is returned,
2971 there is no need to override this function.</p>
2972 <p><b>ADOConnection Fields to Set</b></p>
2973 <p>canSeek: Set to true if the _seek function works.</p>
2974 <h2>ToDo:</h2>
2975 <p>See the <a href=http://php.weblogs.com/adodb-todo-roadmap>RoadMap</a> article.</p>
2976 <p>Also see the ADOdb <a href=http://php.weblogs.com/adodb_csv>proxy</a> article
2977 for bridging Windows and Unix databases using http remote procedure calls. For
2978 your education, visit <a href=http://palslib.com/>palslib.com</a> for database info,
2979 and read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing
2980 PHP</a>. </p>
2981 </font>
2982 <h2>Change Log<a name="Changes"></a><a name="changes"></a><a name="changelog"></a></h2>
2983 <p><b>4.20 27 Feb 2004</b>
2984 <p>Updated to AXMLS 1.01.
2985 <p>MetaForeignKeys for postgres7 modified by Edward Jaramilla, works on pg 7.4.
2986 <p>Now numbers accepts function calls or sequences for GetInsertSQL/GetUpdateSQL numeric fields.
2987 <p>Changed quotes of 'delete from $perf_table' to "". Thx Kehui (webmaster#kehui.net)
2988 <p>Added ServerInfo() for ifx, and putenv trim fix. Thx Fernando Ortiz.
2989 <p>Added addq(), which is analogous to addslashes().
2990 <p>Tested with php5b4. Fix some php5 compat problems with exceptions and sybase.
2991 <P>Carl-Christian Salvesen added patch to mssql _query to support binds greater than 4000 chars.
2992 <p>Mike suggested patch to PHP5 exception handler. $errno must be numeric.
2993 <p>Added double quotes (") to ADODB_TABLE_REGEX.
2994 <p>For oci8, Prepare(...,$cursor), $cursor's meaning was accidentally inverted in 4.11. This causes problems with ExecuteCursor() too, which calls Prepare() internally. Thx to William Lovaton.
2995 <p>Now dateHasTime property in connection object renamed to datetime for consistency. This could break bc.
2996 <p>Csongor Halmai reports that db2 SelectLimit with input array is not working. Fixed..
2997 <p><b>4.11 27 Jan 2004</b>
2998 <p>Csongor Halmai reports db2 binding not working. Reverted back to emulated binding.
2999 <p>Dan Cech modifies datadict code. Adds support for DropIndex. Minor cleanups.
3000 <p>Table misspelt in perf-oci8.inc.php. Changed v$conn_cache_advice to v$db_cache_advice. Reported by Steve W.
3001 <p>UserTimeStamp and DBTimeStamp did not handle YYYYMMDDHHMMSS format properly. Reported by Mike Muir. Fixed.
3002 <p>Changed oci8 Prepare(). Does not auto-allocate OCINewCursor automatically, unless 2nd param is set to true.
3003 This will break backward compat, if Prepare/Execute is used instead of ExecuteCursor. Reported by Chris Jones.
3004 <p>Added InParameter() and OutParameter(). Wrapper functions to Parameter(), but nicer because they
3005 are self-documenting.
3006 <p>Added 'R' handling in ActualType() to datadict-mysql.inc.php
3007 <p>Added ADOConnection::SerializableRS($rs). Returns a recordset that can be serialized in a session.
3008 <p>Added "Run SQL" to performance UI().
3009 <p>Misc spelling corrections in adodb-mysqli.inc.php, adodb-oci8.inc.php and datadict-oci8.inc.php, from Heinz Hombergs.
3010 <p>MetaIndexes() for ibase contributed by Heinz Hombergs.
3011 <p><b>4.10 12 Jan 2004</b>
3012 <p>Dan Cech contributed extensive changes to data dictionary to support name quoting (with `), and drop table/index.
3013 <p>Informix added cursorType property. Default remains IFX_SCROLL, but you can change to 0 (non-scrollable cursor) for performance.
3014 <p>Added ADODB_View_PrimaryKeys() for returning view primary keys to MetaPrimaryKeys().
3015 <p>Simplified chinese file, adodb-cn.inc.php from cysoft.
3016 <p>Added check for ctype_alnum in adodb-datadict.inc.php. Thx to Jason Judge.
3017 <p>Added connection parameter to ibase Prepare(). Fix by Daniel Hassan.
3018 <p>Added nameQuote for quoting identifiers and names to connection obj. Requested by Jason Judge. Also the
3019 data dictionary parser now detects `field name` and generates column names with spaces correctly.
3020 <p>BOOL type not recognised correctly as L. Fixed.
3021 <p>Fixed paths in ADODB_DIR for session files, and back-ported it to 4.05 (15 Dec 2003)
3022 <p>Added Schema to postgresql MetaTables. Thx to col#gear.hu
3023 <p>Empty postgresql recordsets that had blob fields did not set EOF properly. Fixed.
3024 <p>CacheSelectLimit internal parameters to SelectLimit were wrong. Thx to Nio.
3025 <p>Modified adodb_pr() and adodb_backtrace() to support command-line usage (eg. no html).
3026 <p>Fixed some fr and it lang errors. Thx to Gaetano G.
3027 <p>Added contrib directory, with adodb rs to xmlrpc convertor by Gaetano G.
3028 <p>Fixed array recordset bugs when _skiprow1 is true. Thx to Gaetano G.
3029 <p>Fixed pivot table code when count is false.
3032 <p><b>4.05 13 Dec 2003 </b>
3033 <p>Added MetaIndexes - thx to Dan Cech.
3034 <p>Rewritten session code by Ross Smith. Moved code to adodb/session directory.
3035 <p>Added function exists check on connecting to most drivers, so we don't crash with the unknown function error.
3036 <p>Smart Transactions failed with GenID() when it no seq table has been created because the sql
3037 statement fails. Fix by Mark Newnham.
3038 <p>Added $db->length, which holds name of function that returns strlen.
3039 <p>Fixed error handling for bad driver in ADONewConnection - passed too few params to error-handler.
3040 <p>Datadict did not handle types like 16.0 properly in _GetSize. Fixed.
3041 <p>Oci8 driver SelectLimit() bug &= instead of =& used. Thx to Swen Thümmler.
3042 <p>Jesse Mullan suggested not flushing outp when output buffering enabled. Due to Apache 2.0 bug. Added.
3043 <p>MetaTables/MetaColumns return ref bug with PHP5 fixed in adodb-datadict.inc.php.
3044 <p>New mysqli driver contributed by Arjen de Rijke. Based on adodb 3.40 driver.
3045 Then jlim added BeginTrans, CommitTrans, RollbackTrans, IfNull, SQLDate. Also fixed return ref bug.
3046 <p>$ADODB_FLUSH added, if true then force flush in debugging outp. Default is false. In earlier
3047 versions, outp defaulted to flush, which is not compat with apache 2.0.
3048 <p>Mysql driver's GenID() function did not work when when sql logging is on. Fixed.
3049 <p>$ADODB_SESSION_TBL not declared as global var. Not available if adodb-session.inc.php included in function. Fixed.
3050 <p>The input array not passed to Execute() in _adodb_getcount(). Fixed.
3051 <p><b>4.04 13 Nov 2003 </b>
3052 <p>Switched back to foreach - faster than list-each.
3053 <p>Fixed bug in ado driver - wiping out $this->fields with date fields.
3054 <p>Performance Monitor, View SQL, Explain Plan did not work if strlen($SQL)>max($_GET length). Fixed.
3055 <p>Performance monitor, oci8 driver added memory sort ratio.
3056 <p>Added random property, returns SQL to generate a floating point number between 0 and 1;
3057 <p><b>4.03 6 Nov 2003 </b>
3058 <p>The path to adodb-php4.inc.php and adodb-iterators.inc.php was not setup properly.
3059 <p>Patched SQLDate in interbase to support hours/mins/secs. Thx to ari kuorikoski.
3060 <p>Force autorollback for pgsql persistent connections -
3061 apparently pgsql did not autorollback properly before 4.3.4. See http://bugs.php.net/bug.php?id=25404
3062 <p><b>4.02 5 Nov 2003 </b>
3063 <p>Some errors in adodb_error_pg() fixed. Thx to Styve.
3064 <p>Spurious Insert_ID() error was generated by LogSQL(). Fixed.
3065 <p>Insert_ID was interfering with Affected_Rows() and Replace() when LogSQL() enabled. Fixed.
3066 <p>More foreach loops optimized with list/each.
3067 <p>Null dates not handled properly in ADO driver (it becomes 31 Dec 1969!).
3068 <p>Heinz Hombergs contributed patches for mysql MetaColumns - adding scale, made
3069 interbase MetaColumns work with firebird/interbase, and added lang/adodb-de.inc.php.
3070 <p>Added INFORMIXSERVER environment variable.
3071 <p>Added $ADODB_ANSI_PADDING_OFF for interbase/firebird.
3072 <p>PHP 5 beta 2 compat check. Foreach (Iterator) support. Exceptions support.
3073 <p><b>4.01 23 Oct 2003 </b>
3074 <p>Fixed bug in rs2html(), tohtml.inc.php, that generated blank table cells.
3075 <p>Fixed insert_id() incorrectly generated when logsql() enabled.
3076 <p>Modified PostgreSQL _fixblobs to use list/each instead of foreach.
3077 <p>Informix ErrorNo() implemented correctly.
3078 <p>Modified several places to use list/each, including GetRowAssoc().
3079 <p>Added UserTimeStamp() to connection class.
3080 <p>Added $ADODB_ANSI_PADDING_OFF for oci8po.
3081 <p><b>4.00 20 Oct 2003 </b>
3082 <p>Upgraded adodb-xmlschema to 1 Oct 2003 snapshot.
3083 <p>Fix to rs2html warning message. Thx to Filo.
3084 <p>Fix for odbc_mssql/mssql SQLDate(), hours was wrong.
3085 <p>Added MetaColumns and MetaPrimaryKeys for sybase. Thx to Chris Phillipson.
3086 <p>Added autoquoting to datadict for MySQL and PostgreSQL. Suggestion by Karsten Dambekalns
3087 <p><b>3.94 11 Oct 2003 </b>
3088 <p>Create trigger in datadict-oci8.inc.php did not work, because all cr/lf's must be removed.
3089 <p>ErrorMsg()/ErrorNo() did not work for many databases when logging enabled. Fixed.
3090 <p>Removed global variable $ADODB_LOGSQL as it does not work properly with multiple connections.
3091 <p>Added SQLDate support for sybase. Thx to Chris Phillipson
3092 <p>Postgresql checking of pgsql resultset resource was incorrect. Fix by Bharat Mediratta bharat#menalto.com.
3093 Same patch applied to _insertid and _affectedrows for adodb-postgres64.inc.php.
3094 <p>Added support for NConnect for postgresql.
3095 <p>Added Sybase data dict support. Thx to Chris Phillipson
3096 <p>Extensive improvements in $perf->UI(), eg. Explain now opens in new window, we show scripts
3097 which call sql, etc.
3098 <p>Perf Monitor UI works with magic quotes enabled.
3099 <p>rsPrefix was declared twice. Removed.
3100 <p>Oci8 stored procedure support, eg. "begin func(); end;" was incorrect in _query. Fixed.
3101 <p>Tiraboschi Massimiliano contributed italian language file.
3102 <p>Fernando Ortiz, fortiz#lacorona.com.mx, contributed informix performance monitor.
3103 <p>Added _varchar (varchar arrays) support for postgresql. Reported by PREVOT Stéphane.
3104 <p><b>3.92 22 Sept 2003</b>
3105 <p>Added GetAssoc and CacheGetAssoc to connection object.
3106 <p>Removed TextMax and CharMax functions from adodb.inc.php.
3107 <p>HasFailedTrans() returned false when trans failed. Fixed.
3108 <p>Moved perf driver classes into adodb/perf/*.php.
3109 <p>Misc improvements to performance monitoring, including UI().
3110 <p>RETVAL in mssql Parameter(), we do not append @ now.
3111 <p>Added Param($name) to connection class, returns '?' or ":$name", for defining
3112 bind parameters portably.
3113 <p>LogSQL traps affected_rows() and saves its value properly now. Also fixed oci8
3114 _stmt and _affectedrows() bugs.
3115 <p>Session code timestamp check for oci8 works now. Formerly default NLS_DATE_FORMAT
3116 stripped off time portion. Thx to Tony Blair (tonanbarbarian#hotmail.com). Also
3117 added new $conn->datetime field to oci8, controls whether MetaType() returns
3118 'D' ($this->datetime==false) or 'T' ($this->datetime == true) for DATE type.
3119 <p>Fixed bugs in adodb-cryptsession.inc.php and adodb-session-clob.inc.php.
3120 <p>Fixed misc bugs in adodb_key_exists, GetInsertSQL() and GetUpdateSQL().
3121 <p>Tuned include_once handling to reduce file-system checking overhead.
3122 <p><b>3.91 9 Sept 2003</b>
3123 <p>Only released to InterAkt
3124 <p>Added LogSQL() for sql logging and $ADODB_NEWCONNECTION to override factory
3125 for driver instantiation.
3126 <p>Added IfNull($field,$ifNull) function, thx to johnwilk#juno.com
3127 <p>Added portable substr support.
3128 <p>Now rs2html() has new parameter, $echo. Set to false to return $html instead
3129 of echoing it.
3130 <p><b>3.90 5 Sept 2003</b>
3131 <p>First beta of performance monitoring released.
3132 <p>MySQL supports MetaTable() masking.
3133 <p>Fixed key_exists() bug in adodb-lib.inc.php
3134 <p>Added sp_executesql Prepare() support to mssql.
3135 <p>Added bind support to db2.
3136 <p>Added swedish language file - Christian Tiberg" christian#commsoft.nu
3137 <p>Bug in drop index for mssql data dict fixed. Thx to Gert-Rainer Bitterlich.
3138 <p>Left join setting for oci8 was wrong. Thx to johnwilk#juno.com
3139 <p><b>3.80 27 Aug 2003</b>
3140 <p>Patch for PHP 4.3.3 cached recordset csv2rs() fread loop incompatibility.
3141 <p>Added matching mask for MetaTables. Only for oci8, mssql and postgres currently.
3142 <p>Rewrite of "oracle" driver connection code, merging with "oci8", by Gaetano.
3143 <p>Added better debugging for Smart Transactions.
3144 <p>Postgres DBTimeStamp() was wrongly using TO_DATE. Changed to TO_TIMESTAMP.
3145 <p>ADODB_FETCH_CASE check pushed to ADONewConnection to allow people to define
3146 it after including adodb.inc.php.
3147 <p>Added portugese (brazilian) to languages. Thx to "Levi Fukumori".
3148 <p>Removed arg3 parameter from Execute/SelectLimit/Cache* functions.
3149 <p>Execute() now accepts 2-d array as $inputarray. Also changed docs of fnExecute()
3150 to note change in sql query counting with 2-d arrays.
3151 <p>Added MONEY to MetaType in PostgreSQL.
3152 <p>Added more debugging output to CacheFlush().
3153 <p><b>3.72 9 Aug 2003</b>
3154 <p>Added qmagic($str), which is a qstr($str) that auto-checks for magic quotes
3155 and does the right thing...
3156 <p>Fixed CacheFlush() bug - Thx to martin#gmx.de
3157 <p>Walt Boring contributed MetaForeignKeys for postgres7.
3158 <p>_fetch() called _BlobDecode() wrongly in interbase. Fixed.
3159 <p>adodb_time bug fixed with dates after 2038 fixed by Jason Pell. http://phplens.com/lens/lensforum/msgs.php?id=6980
3160 <p><b>3.71 4 Aug 2003</b>
3161 <p>The oci8 driver, MetaPrimaryKeys() did not check the owner correctly when $owner
3162 == false.
3163 <p>Russian language file contributed by "Cyrill Malevanov" cyrill#malevanov.spb.ru.
3164 <p>Spanish language file contributed by "Horacio Degiorgi" horaciod#codigophp.com.
3165 <p>Error handling in oci8 bugfix - if there was an error in Execute(), then when
3166 calling ErrorNo() and/or ErrorMsg(), the 1st call would return the error, but
3167 the 2nd call would return no error.
3168 <p>Error handling in odbc bugfix. ODBC would always return the last error, even
3169 if it happened 5 queries ago. Now we reset the errormsg to '' and errorno to
3170 0 everytime before CacheExecute() and Execute().
3171 <p><b>3.70 29 July 2003</b>
3172 <p>Added new SQLite driver. Tested on PHP 4.3 and PHP 5.
3173 <p>Added limited "sapdb" driver support - mainly date support.
3174 <p>The oci8 driver did not identify NUMBER with no defined precision correctly.
3175 <p>Added ADODB_FORCE_NULLS, if set, then PHP nulls are converted to SQL nulls
3176 in GetInsertSQL/GetUpdateSQL.
3177 <p>DBDate() and DBTimeStamp() format for postgresql had problems. Fixed.
3178 <p>Added tableoptions to ChangeTableSQL(). Thx to Mike Benoit.
3179 <p>Added charset support to postgresql. Thx to Julian Tarkhanov.
3180 <p>Changed OS check for MS-Windows to prevent confusion with darWIN (MacOS)
3181 <p>Timestamp format for db2 was wrong. Changed to yyyy-mm-dd-hh.mm.ss.nnnnnn.
3182 <p>adodb-cryptsession.php includes wrong. Fixed.
3183 <p>Added MetaForeignKeys(). Supported by mssql, odbc_mssql and oci8.
3184 <p>Fixed some oci8 MetaColumns/MetaPrimaryKeys bugs. Thx to Walt Boring.
3185 <p>adodb_getcount() did not init qryRecs to 0. Missing "WHERE" clause checking
3186 in GetUpdateSQL fixed. Thx to Sebastiaan van Stijn.
3187 <p>Added support for only 'VIEWS' and "TABLES" in MetaTables. From Walt Boring.
3188 <p>Upgraded to adodb-xmlschema.inc.php 0.0.2.
3189 <p>NConnect for mysql now returns value. Thx to Dennis Verspuij.
3190 <p>ADODB_FETCH_BOTH support added to interbase/firebird.
3191 <p>Czech language file contributed by Kamil Jakubovic jake#host.sk.
3192 <p>PostgreSQL BlobDecode did not use _connectionID properly. Thx to Juraj Chlebec.
3193 <p>Added some new initialization stuff for Informix. Thx to "Andrea Pinnisi" pinnisi#sysnet.it
3194 <p>ADODB_ASSOC_CASE constant wrong in sybase _fetch(). Fixed.
3195 <p><b>3.60 16 June 2003</b>
3196 <p>We now SET CONCAT_NULL_YIELDS_NULL OFF for odbc_mssql driver to be compat with
3197 mssql driver.
3198 <p>The property $emptyDate missing from connection class. Also changed 1903 to
3199 constant (TIMESTAMP_FIRST_YEAR=100). Thx to Sebastiaan van Stijn.
3200 <p>ADOdb speedup optimization - we now return all arrays by reference.
3201 <p>Now DBDate() and DBTimeStamp() now accepts the string 'null' as a parameter.
3202 Suggested by vincent.
3203 <p>Added GetArray() to connection class.
3204 <p>Added not_null check in informix metacolumns().
3205 <p>Connection parameters for postgresql did not work correctly when port was defined.
3206 <p>DB2 is now a tested driver, making adodb 100% compatible. Extensive changes
3207 to odbc driver for DB2, including implementing serverinfo() and SQLDate(), switching
3208 to SQL_CUR_USE_ODBC as the cursor mode, and lastAffectedRows and SelectLimit()
3209 fixes.
3210 <p>The odbc driver's FetchField() field names did not obey ADODB_ASSOC_CASE. Fixed.
3211 <p>Some bugs in adodb_backtrace() fixed.
3212 <p>Added "INT IDENTITY" type to adorecordset::MetaType() to support odbc_mssql
3213 properly.
3214 <p>MetaColumns() for oci8, mssql, odbc revised to support scale. Also minor revisions
3215 to odbc MetaColumns() for vfp and db2 compat.
3216 <p>Added unsigned support to mysql datadict class. Thx to iamsure.
3217 <p>Infinite loop in mssql MoveNext() fixed when ADODB_FETCH_ASSOC used. Thx to
3218 Josh R, Night_Wulfe#hotmail.com.
3219 <p>ChangeTableSQL contributed by Florian Buzin.
3220 <p>The odbc_mssql driver now sets CONCAT_NULL_YIELDS_NULL OFF for compat with
3221 mssql driver.
3222 <hr>
3223 <p><strong>0.10 Sept 9 2000</strong> First release
3224 <h3><strong>Old changelog history moved to <a href=old-changelog.htm>old-changelog.htm</a>.
3225 </strong></h3>
3226 <p>&nbsp;</p>
3227 <p> </font>
3228 </body>
3229 </html>