Location: PHPKode > projects > Huygens Remote Manager > hrm/inc/extern/adodb/docs/docs-adodb.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>ADODB Manual</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

pre {
  background-color: #eee;
  padding: 0.75em 1.5em;
  font-size: 12px;
  border: 1px solid #ddd;
<body bgcolor="#ffffff" text="black">

<h2>ADOdb Library for PHP</h2>
<p>V4.92a 29 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com)</p>
<p><font size="1">This software is dual licensed using BSD-Style and LGPL. This 
  means you can use it in compiled proprietary and commercial products.</font></p>

	<p>Useful ADOdb links:  <a href="http://adodb.sourceforge.net/#download">Download</a> &nbsp; <a href="http://adodb.sourceforge.net/#docs">Other Docs</a>

</p><p><a href="#intro"><b>Introduction</b></a><b><br>
	<a href="#features">Unique Features</a><br>
	<a href="#users">How People are using ADOdb</a><br>
	<a href="#bugs">Feature Requests and Bug Reports</a><br>
	</b><b><a href="#install">Installation</a><br>
	<a href="#mininstall">Minimum Install</a><br>
	<a href="#coding">Initializing Code and Connectioning to Databases</a><br>
	</b><font size="2"> &nbsp; <a href="#dsnsupport">Data Source Name (DSN) Support</a></font>  &nbsp;  <a href="#connect_ex">Connection Examples</a> <br>
	<b><a href="#speed">High Speed ADOdb - tuning tips</a></b><br>
	<b><a href="#hack">Hacking and Modifying ADOdb Safely</a><br>
	<a href="#php5">PHP5 Features</a></b><br>
	<font size="2"><a href="#php5iterators">foreach iterators</a> <a href="#php5exceptions">exceptions</a></font><br>
	<b> <a href="#drivers">Supported Databases</a></b><br>
	<b> <a href="#quickstart">Tutorials</a></b><br>
	<a href="#ex1">Example 1: Select</a><br>
	<a href="#ex2">Example 2: Advanced Select</a><br>
	<a href="#ex3">Example 3: Insert</a><br>
	<a href="#ex4">Example 4: Debugging</a> &nbsp;<a href="#exrs2html">rs2html 
	<a href="#ex5">Example 5: MySQL and Menus</a><br>
	<a href="#ex6">Example 6: Connecting to Multiple Databases at once</a> <br>
	<a href="#ex7">Example 7: Generating Update and Insert SQL</a> <br>
	<a href="#ex8">Example 8: Implementing Scrolling with Next and Previous</a><br>
	<a href="#ex9">Example 9: Exporting in CSV or Tab-Delimited Format</a> <br>
	<a href="#ex10">Example 10: Custom filters</a><br>
	<a href="#ex11">Example 11: Smart Transactions</a><br>
	<b> <a href="#errorhandling">Using Custom Error Handlers and PEAR_Error</a><br>
	<a href="#DSN">Data Source Names</a><br>
	<a href="#caching">Caching</a><br>
	<a href="#pivot">Pivot Tables</a></b> 
</p><p><a href="#ref"><b>REFERENCE</b></a>
</p><p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> 
<a href="#adodb_ansi_padding_off">$ADODB_ANSI_PADDING_OFF</a>
  <a href="#adodb_cache_dir">$ADODB_CACHE_DIR</a> <br>
  &nbsp; &nbsp; &nbsp; &nbsp;  <a href="#force_type">$ADODB_FORCE_TYPE</a> 
  <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a> 
  <a href="#adodb_lang">$ADODB_LANG</a> <br>
  Constants: </font><font size="2"><a href="#adodb_assoc_case">ADODB_ASSOC_CASE</a> 
  <a href="#ADOConnection"><b> ADOConnection</b></a><br>
  <font size="2">Connections: <a href="#connect">Connect</a> <a href="#pconnect">PConnect</a> 
  <a href="#nconnect">NConnect</a> <a href="#isconnected">IsConnected</a><br>
  Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute"><i>CacheExecute</i></a> 
  <a href="#selectlimit">SelectLimit</a> <a href="#cacheSelectLimit"><i>CacheSelectLimit</i></a> 
  <a href="#param">Param</a> <a href="#prepare">Prepare</a> <a href="#preparesp">PrepareSP</a> 
  <a href="#inparameter">InParameter</a> <a href="#outparameter">OutParameter</a> <a href="#autoexecute">AutoExecute</a>
  &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#getone">GetOne</a> 
  <a href="#cachegetone"><i>CacheGetOne</i></a> <a href="#getrow">GetRow</a> <a href="#cachegetrow"><i>CacheGetRow</i></a> 
  <a href="#getall">GetAll</a> <a href="#cachegetall"><i>CacheGetAll</i></a> <a href="#getcol">GetCol</a> 
  <a href="#cachegetcol"><i>CacheGetCol</i></a> <a href="#getassoc1">GetAssoc</a> <a href="#cachegetassoc"><i>CacheGetAssoc</i></a> <a href="#replace">Replace</a> 
  &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#executecursor">ExecuteCursor</a> 
  (oci8 only)<br>
  Generates SQL strings: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a> 
  <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> 
  <a href="#qstr">qstr</a> <a href="#param">Param</a>  <a href="#OffsetDate">OffsetDate</a> <a href="#SQLDate">SQLDate</a> 
  <a href="#dbdate">DBDate</a>  <a href="#dbtimestamp">DBTimeStamp</a>
  <a href="#binddate">BindDate</a>  <a href="#bindtimestamp">BindTimeStamp</a>
  Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a> 
  <a href="#updateblobfile">UpdateBlobFile</a> <a href="#blobencode">BlobEncode</a> 
  <a href="#blobdecode">BlobDecode</a><br>
  Paging/Scrolling: <a href="#pageexecute">PageExecute</a> <a href="#cachepageexecute">CachePageExecute</a><br>
  Cleanup: <a href="#cacheflush">CacheFlush</a> <a href="#Close">Close</a><br>
  Transactions: <a href="#starttrans">StartTrans</a> <a href="#completetrans">CompleteTrans</a> 
  <a href="#failtrans">FailTrans</a> <a href="#hasfailedtrans">HasFailedTrans</a> 
  <a href="#begintrans">BeginTrans</a> <a href="#committrans">CommitTrans</a> 
  <a href="#rollbacktrans">RollbackTrans</a> <a href=#SetTransactionMode>SetTransactionMode</a><br>
  Fetching Data: </font> <font size="2"><a href="#setfetchmode">SetFetchMode</a><br>
  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>
  Dates: <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> <a href="#unixdate">UnixDate</a> 
  <a href="#binddate">BindDate</a>  <a href="#bindtimestamp">BindTimeStamp</a>
  <a href="#unixtimestamp">UnixTimeStamp</a> <a href="#OffsetDate">OffsetDate</a> 
  <a href="#SQLDate">SQLDate</a> <br>
  Row Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a>  <a href="#rowlock">RowLock</a>
  <a href="#genid">GenID</a> <a href="#createseq">CreateSequence</a> <a href="#dropseq">DropSequence</a> 
  Error Handling: <a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a> 
  <a href="#metaerror">MetaError</a> <a href="#metaerrormsg">MetaErrorMsg</a> <a href="#ignoreerrors">IgnoreErrors</a><br>
  Data Dictionary (metadata): <a href="#metadatabases">MetaDatabases</a> <a href="#metatables">MetaTables</a> 
  <a href="#metacolumns">MetaColumns</a> <a href="#metacolumnames">MetaColumnNames</a> 
  <a href="#metaprimarykeys">MetaPrimaryKeys</a> <a href="#metaforeignkeys">MetaForeignKeys</a> 
  <a href="#serverinfo">ServerInfo</a> <br>
  Statistics and Query-Rewriting: <a href="#logsql">LogSQL</a> <a href="#fnexecute">fnExecute 
  and fnCacheExecute</a><br>
  </font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a>
  <a href="#parameter">Parameter</a></font>
  <a href="#adorecordSet"><b><br>
  <font size="2">
  Returns one field: <a href="#fields">Fields</a><br>
 Returns one row:<a href="#fetchrow">FetchRow</a> <a href="#fetchinto">FetchInto</a> 
  <a href="#fetchobject">FetchObject</a> <a href="#fetchnextobject">FetchNextObject</a> 
  <a href="#fetchobj">FetchObj</a> <a href="#fetchnextobj">FetchNextObj</a>
 <a href="#getrowassoc">GetRowAssoc</a> <br>
  Returns all rows:<a href="#getarray">GetArray</a> <a href="#getrows">GetRows</a> 
  <a href="#getassoc">GetAssoc</a><br>
  Scrolling:<a href="#move">Move</a> <a href="#movenext">MoveNext</a> <a href="#movefirst">MoveFirst</a> 
  <a href="#movelast">MoveLast</a> <a href="#abspos">AbsolutePosition</a> <a href="#currentrow">CurrentRow</a> 
  <a href="#atfirstpage">AtFirstPage</a> <a href="#atlastpage">AtLastPage</a> 
  <a href="#absolutepage">AbsolutePage</a> </font> <font size="2"><br>
  Menu generation:<a href="#getmenu">GetMenu</a> <a href="#getmenu2">GetMenu2</a><br>
  Dates:<a href="#userdate">UserDate</a> <a href="#usertimestamp">UserTimeStamp</a> 
  <a href="#unixdate">UnixDate</a> <a href="#unixtimestamp">UnixTimeStamp<br>
  </a>Recordset Info:<a href="#recordcount">RecordCount</a> <a href="#po_recordcount">PO_RecordCount</a> 
  <a href="#nextrecordset">NextRecordSet</a><br>
  Field Info:<a href="#fieldcount">FieldCount</a> <a href="#fetchfield">FetchField</a> 
  <a href="#metatype">MetaType</a><br>
  Cleanup: <a href="#rsclose">Close</a></font>  
<p><font size="2"><a href="#rs2html"><b>rs2html</b></a>&nbsp; <a href="#exrs2html">example</a></font><br>
  <a href="#adodiff">Differences between ADOdb and ADO</a><br>
  <a href="#driverguide"><b>Database Driver Guide<br>
  </b></a><b><a href="#changes">Change Log</a></b><br>
<h2>Introduction<a name="intro"></a></h2>
<p>PHP's database access functions are not standardised. This creates a need for 
  a database class library to hide the differences between the different database 
  API's (encapsulate the differences) so we can easily switch databases. PHP 4.0.5 or later
  is now required (because we use array-based str_replace).</p>
<p>We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, 
  PostgreSQL, FrontBase,  SQLite, Interbase (Firebird and Borland variants), Foxpro, Access, ADO, DB2, SAP DB and ODBC. 
  We have had successful reports of connecting to Progress and CacheLite via ODBC. We hope more people 
  will contribute drivers to support other databases.</p>
<p>PHP4 supports session variables. You can store your session information using 
  ADOdb for true portability and scalability. See adodb-session.php for more information.</p>
<p>Also read <a href="http://phplens.com/lens/adodb/tips_portable_sql.htm">tips_portable_sql.htm</a> 
 for tips on writing 
  portable SQL.</p>
<h2>Unique Features of ADOdb<a name="features"></a></h2>
  <li><b>Easy for Windows programmers</b> to adapt to because many of the conventions 
	are similar to Microsoft's ADO.</li>
  <li>Unlike other PHP database classes which focus only on select statements, 
	<b>we provide support code to handle inserts and updates which can be adapted 
	to multiple databases quickly.</b> Methods are provided for date handling, 
	string concatenation and string quoting characters for differing databases.</li>
  <li>A<b> metatype system </b>is built in so that we can figure out that types 
	such as CHAR, TEXT and STRING are equivalent in different databases.</li>
  <li><b>Easy to port</b> because all the database dependant code are stored in 
	stub functions. You do not need to port the core logic of the classes.</li>
  <li><b>Portable table and index creation</b> with the <a href="docs-datadict.htm">datadict</a> classes.
  </li><li><b>Database performance monitoring and SQL tuning</b> with the <a href="docs-perf.htm">performance monitoring</a> classes.
  </li><li><b>Database-backed sessions</b> with the <a href="docs-session.htm">session management</a> classes. Supports session expiry notification.
<li><b>Object-Relational Mapping</b> using <a href="docs-active-record.htm">ADOdb_Active_Record</a> classes.
<h2>How People are using ADOdb<a name="users"></a></h2>
Here are some examples of how people are using ADOdb (for a much longer list, 
visit <a href="http://phplens.com/phpeverywhere/adodb-cool-apps">adodb-cool-apps</a>): 
<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>

</p></li><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>

</p></li><li><a href="http://www.andrew.cmu.edu/%7Erdanyliw/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>

</p></li><li><a href="http://www.postnuke.com/">PostNuke</a> is a very
popular free content management 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>

</p></li><li><a href="http://www.auto-net.no/easypublish.php?page=index&amp;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

</p></li><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.

</p><h2>Feature Requests and Bug Reports<a name="bugs"></a></h2>
<p>Feature requests and bug reports can be emailed to <a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a> 
  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>
<h2>Installation Guide<a name="install"></a></h2>
<p>Make sure you are running PHP 4.0.5 or later. 
  Unpack all the files into a directory accessible by your webserver.</p>
<p>To test, try modifying some of the tutorial examples. Make sure you customize 
  the connection settings correctly. You can debug using <i>$db-&gt;debug = true</i> as shown below:</p>
<pre>&lt;?php<br>	include('adodb/adodb.inc.php');<br>	$db = <a href="#adonewconnection">ADONewConnection</a>($dbdriver); # eg 'mysql' or 'postgres'<br>	$db-&gt;debug = true;<br>	$db-&gt;<a href="#connect">Connect</a>($server, $user, $password, $database);<br>	$rs = $db-&gt;<a href="#execute">Execute</a>('select * from some_small_table');<br>	print "&lt;pre&gt;";<br>	print_r($rs-&gt;<a href="#getrows">GetRows</a>());<br>	print "&lt;/pre&gt;";<br>?&gt;</pre>

 <h3>Minimum Install<a name="mininstall"></a></h3>
<p>For developers who want to release a minimal install of ADOdb, you will need:
</li><li>license.txt (for legal reasons)
</li><li>adodb-iterator.inc.php  (php5 functionality)
<li>adodb-error.inc.php and lang/adodb-$lang.inc.php (if you use MetaError())
</li><li>adodb-csvlib.inc.php (if you use cached recordsets - CacheExecute(), etc)
</li><li>adodb-exceptions.inc.php and adodb-errorhandler.inc.php (if you use adodb error handler or php5 exceptions).
<li>adodb-active-record.inc.php if you use <a href=docs-active-record.htm>Active Records</a>.

<h3>Code Initialization Examples<a name="coding"></a></h3>
<p>When running ADOdb, at least two files are loaded. First is adodb/adodb.inc.php, 
 which contains all functions used by all database classes. The code specific 
 to a particular database is in the adodb/driver/adodb-????.inc.php file.</p>
 <a name="adonewconnection"></a>
<p>For example, to connect to a mysql database:</p>
<pre>include('/path/to/set/here/adodb.inc.php');<br>$conn = &amp;ADONewConnection('mysql');<br></pre>
<p>Whenever you need to connect to a database, you create a Connection object 
  using the <b>ADONewConnection</b>($driver) function. 
  <b>NewADOConnection</b>($driver) is an alternative name for the same function.</p>

<p>At this point, you are not connected to the database (no longer true if you pass in a <a href="#dsnsupport">dsn</a>). You will first need to decide
whether to use <i>persistent</i> or <i>non-persistent</i> connections. The advantage of <i>persistent</i>
connections is that they are faster, as the database connection is never closed (even 
when you call Close()). <i>Non-persistent </i>connections take up much fewer resources though,
reducing the risk of your database and your web-server becoming overloaded. 
</p><p>For persistent connections,
use $conn-&gt;<a href="#pconnect">PConnect()</a>,
 or $conn-&gt;<a href="#connect">Connect()</a> for non-persistent connections.
Some database drivers also support <a href="#nconnect">NConnect()</a>, which forces 
the creation of a new connection. 

<a name="connection_gotcha"></a>
</p><p><b>Connection Gotcha</b>:  If you create two connections, but both use the same userid and password,
PHP will share the same connection. This can cause problems if the connections are meant to 
different databases. The solution is to always use different userid's for different databases,
 or use NConnect().

 <a name="dsnsupport"></a>
 </p><h3>Data Source Name (DSN) Support</h3>
 <p> Since ADOdb 4.51, you can connect to a database by passing a dsn to NewADOConnection() (or ADONewConnection, which is
 the same function). The dsn format is:
</p><pre>	$driver://$username:$hide@address.com/$database?options[=value]<br></pre><p>
NewADOConnection() calls Connect() or PConnect() internally for you. If the connection fails, false is returned.
</p><pre>	<font color="#008000"># non-persistent connection</font>
	$dsn = 'mysql://root:hide@address.com/mydb'; 
	$db = NewADOConnection($dsn);
	if (!$db) die("Connection failed");   
	<font color="#008000"># no need to call connect/pconnect!</font>
	$arr = $db-&gt;GetArray("select * from table");
	<font color="#008000"># persistent connection</font>
	$dsn2 = 'mysql://root:hide@address.com/mydb?persist'; 
If you have special characters such as /:?_ in your dsn, then you need to rawurlencode them first:
</p><pre>	$pwd = rawurlencode($pwd);<br>	$dsn = "mysql://root:$hide@address.com/mydb";
Legal options are:
<table align="center" border="1"><tbody><tr><td>For all drivers</td><td>
	'persist', 'persistent', 'debug', 'fetchmode', 'new'
	</td></tr><tr><td>M'soft ADO</td><td>
	'port', 'socket', 'clientflags'
For all drivers, when the options <i>persist</i> or <i>persistent</i> are set,  a persistent connection is forced; similarly, when <i>new</i> is set, then
a new connection will be created using NConnect if the underlying driver supports it. 
The <i>debug</i> option enables debugging. The <i>fetchmode</i> calls <a href="#setfetchmode">SetFetchMode()</a>.
If no value is defined for an option, then the value is set to 1.
ADOdb DSN's are compatible with version 1.0 of PEAR DB's DSN format.
<a name="connect_ex">
</a></p><h3><a name="connect_ex">Examples of Connecting to Databases</a></h3>
<h4><a name="connect_ex">MySQL and Most Other Database Drivers</a></h4>
<p><a name="connect_ex">MySQL connections are very straightforward, and the parameters are identical 
  to mysql_connect:</a></p>
<pre><a name="connect_ex">	$conn = &amp;ADONewConnection('mysql'); <br>	$conn-&gt;PConnect('localhost','userid','password','database');<br>	<br>	<font color="#008000"># or dsn </font>
	$dsn = 'mysql://user:hide@address.com/mydb'; 
	$conn = ADONewConnection($dsn);  # no need for Connect()
	<font color="#008000"># or persistent dsn</font>
	$dsn = 'mysql://user:hide@address.com/mydb?persist'; 
	$conn = ADONewConnection($dsn);  # no need for PConnect()
	<font color="#008000"># a more complex example:</font>
	$pwd = urlencode($pwd);
	$dsn = "mysql://user:$hide@address.com/mydb?persist&amp;clientflags=$flags";
	$conn = ADONewConnection($dsn);  # no need for PConnect()
<p><a name="connect_ex"> For most drivers, you can use the standard function: Connect($server, $user, $password, $database), or
a </a><a href="dsnsupport">DSN</a> since ADOdb 4.51. Exceptions to this are listed below.
<a name=pdo>
<p>PDO, which only works with PHP5, accepts a driver specific connection string:
	$conn =& NewADConnection('pdo');
<p>The DSN mechanism is also supported:
	$conn =& NewADConnection("pdo_mysql://user:hide@address.com/mydb?persist"); # persist is optional
<p>PostgreSQL 7 and 8 accepts connections using: </p>
<p>a. the standard connection string:</p>
<pre>	$conn = &amp;ADONewConnection('postgres');  <br>	$conn-&gt;PConnect('host=localhost port=5432 dbname=mary');</pre>
<p> b. the classical 4 parameters:</p>
 <pre>	$conn-&gt;PConnect('localhost','userid','password','database');<br> </pre>
<p>c. dsn:
</p><pre>	$dsn = 'postgres://user:hide@address.com/mydb?persist';  # persist is optional
	$conn = ADONewConnection($dsn);  # no need for Connect/PConnect<br></pre>
<a name="ldap"></a>

  <p>Here is an example of querying a LDAP server. Thanks to Josh Eldridge for the driver and this example:

/* Make sure to set this BEFORE calling Connect() */
$host = 'ldap.baylor.edu';
$ldapbase = 'ou=People,o=Baylor University,c=US';

$ldap = NewADOConnection( 'ldap' );
$ldap->Connect( $host, $user_name='', $password='', $ldapbase );

echo "&lt;pre>";

print_r( $ldap->ServerInfo() );
$userName = 'eldridge';

$rs = $ldap->Execute( $filter );
if ($rs)
	while ($arr = $rs->FetchRow()) {

$rs = $ldap->Execute( $filter );
if ($rs) 
	while (!$rs->EOF) {
print_r( $ldap->GetArray( $filter ) );
print_r( $ldap->GetRow( $filter ) );

echo "&lt;/pre>";
<p>Using DSN:
$dsn = "ldap://ldap.baylor.edu/ou=People,o=Baylor University,c=US";
$db = NewADOConnection($dsn);
You define the database in the $host parameter:
<pre>	$conn = &amp;ADONewConnection('ibase'); <br>	$conn-&gt;PConnect('localhost:c:\ibase\employee.gdb','sysdba','masterkey');<br></pre>
<p>Or dsn:
</p><pre>	$dsn = 'firebird://user:hide@address.com/mydb?persist&amp;dialect=3';  # persist is optional<br>	$conn = ADONewConnection($dsn);  # no need for Connect/PConnect<br></pre>
Sqlite will create the database file if it does not exist.
<pre>	$conn = &amp;ADONewConnection('sqlite');
	$conn-&gt;PConnect('c:\path\to\sqlite.db'); # sqlite will create if does not exist<br></pre>
<p>Or dsn:
</p><pre>	$path = urlencode('c:\path\to\sqlite.db');
	$dsn = "sqlite://$path/?persist";  # persist is optional
	$conn = ADONewConnection($dsn);  # no need for Connect/PConnect<br></pre>
<h4>Oracle (oci8)</h4>
<p>With oci8, you can connect in multiple ways. Note that oci8 works fine with 
newer versions of the Oracle, eg. 9i and 10g.</p>
<p>a. PHP and Oracle reside on the same machine, use default SID.</p>
<pre>	$conn-&gt;Connect(false, 'scott', 'tiger');</pre>
<p>b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS'</p>
<pre>	$conn-&gt;PConnect(false, 'scott', 'tiger', 'myTNS');</pre>
<pre> 	$conn-&gt;PConnect('myTNS', 'scott', 'tiger');</pre>
<p>c. Host Address and SID</p>
	$conn->connectSID = true;
	$conn-&gt;Connect('', 'scott', 'tiger', 'SID');</pre>
<p>d. Host Address and Service Name</p>
<pre>	$conn-&gt;Connect('', 'scott', 'tiger', 'servicename');</pre>
<p>e. Oracle connection string:
</p><pre>	$cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port))<br>			(CONNECT_DATA=(SID=$sid)))";<br>	$conn-&gt;Connect($cstr, 'scott', 'tiger');<br></pre>
<p>f. ADOdb dsn:
</p><pre>	$dsn = 'oci8://user:hide@address.com/?persist';  # persist is optional<br>	$conn = ADONewConnection($dsn);  # no need for Connect/PConnect<br>	<br>	$dsn = 'oci8://user:hide@address.com/sid';<br>	$conn = ADONewConnection($dsn);<br>	<br>	$dsn = 'oci8://user:pwd@/';   # oracle on local machine<br>	$conn = ADONewConnection($dsn);<br></pre>
<p>You can also set the charSet for Oracle 9.2 and later, supported since PHP 4.3.2, ADOdb 4.54:
</p><pre>	$conn-&gt;charSet = 'we8iso8859p1';<br>	$conn-&gt;Connect(...);<br>	<br>	# or<br>	$dsn = 'oci8://user:hide@address.com/?charset=WE8MSWIN1252';<br>	$db = ADONewConnection($dsn);<br></pre>
<a name="dsnless"></a>
<h4>DSN-less ODBC ( Access, MSSQL and DB2 examples)</h4>
<p>ODBC DSN's can be created in the ODBC control panel, or you can use a DSN-less 
  connection.To use DSN-less connections with ODBC you need PHP 4.3 or later. 
<p>For Microsoft Access:</p>
<pre>	$db =&amp; ADONewConnection('access');<br>	$dsn = <strong>"Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;";</strong>
For Microsoft SQL Server: 
<pre>	$db =&amp; ADONewConnection('odbc_mssql');<br>	$dsn = <strong>"Driver={SQL Server};Server=localhost;Database=northwind;"</strong>;<br>	$db-&gt;Connect($dsn,'userid','password');<br></pre>
or if you prefer to use the mssql extension (which is limited to mssql 6.5 functionality):
<pre>	$db =&amp; ADONewConnection('mssql');<br>	$db-&gt;Execute('localhost', 'userid', 'password', 'northwind');<br></pre>
For DB2:
	$dbms = 'db2'; # or 'odbc_db2' if db2 extension not available
	$db =&amp; ADONewConnection($dbms);
	$dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP;".
				"uid=root; pwd=secret";<br>	$db-&gt;Connect($dsn);
<b>DSN-less Connections with ADO</b><br>
If you are using versions of PHP earlier than PHP 4.3.0, DSN-less connections 
only work with Microsoft's ADO, which is Microsoft's COM based API. An example 
using the ADOdb library and Microsoft's ADO: 
<pre>&lt;?php<br>	include('adodb.inc.php'); <br>	$db = &amp;ADONewConnection("ado_mssql");<br>	print "&lt;h1&gt;Connecting DSN-less $db-&gt;databaseType...&lt;/h1&gt;";<br>		<br>	<b>$myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"<br>		. "SERVER=flipper;DATABASE=ai;UID=sa;PWD=;"  ;</b>
	$rs = $db-&gt;Execute("select * from table");
	$arr = $rs-&gt;GetArray();
</pre><a name="speed"></a>
<h2>High Speed ADOdb - tuning tips</h2>
<p>ADOdb is a big class library, yet it <a href="http://phplens.com/lens/adodb/">consistently beats</a> all other PHP class 
  libraries in performance. This is because it is designed in a layered fashion, 
  like an onion, with the fastest functions in the innermost layer. Stick to the 
  following functions for best performance:</p>
<table align="center" border="1" width="40%">
    <td><div align="center"><b>Innermost Layer</b></div></td>
    <td><p align="center">Connect, PConnect, NConnect<br>
        Execute, CacheExecute<br>
        SelectLimit, CacheSelectLimit<br>
        MoveNext, Close <br>
		qstr, Affected_Rows, Insert_ID</p></td>
<p>The fastest way to access the field data is by accessing the array $recordset-&gt;fields 
  directly. Also set the global variables <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a> 
  = ADODB_FETCH_NUM, and (for oci8, ibase/firebird and odbc) <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> = false 
  before you connect to your database.</p>
<p>Consider using bind parameters if your database supports it, as it improves 
  query plan reuse. Use ADOdb's performance tuning system to identify bottlenecks 
  quickly. At the time of writing (Dec 2003), this means oci8 and odbc drivers.</p>
 <p>Lastly make sure you have a PHP accelerator cache installed such as APC, Turck 
  MMCache, Zend Accelerator or ionCube.</p>
 <p>Some examples:</p>
 <table align="center" border="1"><tbody><tr><td><b>Fastest data retrieval using PHP</b></td><td><b>Fastest data retrieval using ADOdb extension</b></td></tr>
<pre>$rs =&amp; $rs-&gt;Execute($sql);<br>while (!$rs-&gt;EOF) {<br>	var_dump($rs-&gt;fields);<br>	$rs-&gt;MoveNext();<br>}</pre></td><td>
<pre>$rs =&amp; $rs-&gt;Execute($sql);<br>$array = adodb_getall($rs);<br>var_dump($array);<br><br><br></pre></td></tr></tbody></table>
 <p><b>Advanced Tips</b>
 </p><p>If you have the <a href="http://adodb.sourceforge.net/#extension">ADOdb C extension</a> installed, 
 you can replace your calls to $rs-&gt;MoveNext() with adodb_movenext($rs). 
 This doubles the speed of this operation. For retrieving entire recordsets at once,
use GetArray(), which uses the high speed extension function adodb_getall($rs) internally.
 </p><p>Execute() is the default way to run queries. You can use the low-level functions _Execute() and _query()
to reduce query overhead.  Both these functions share the same parameters as Execute().
</p><p>If you do not have any bind parameters or your database supports
binding (without emulation),
then you can call _Execute() directly. Calling this function bypasses
bind emulation. Debugging is still supported in _Execute().
</p><p>If you do not require debugging facilities nor emulated
binding, and do not require a recordset to be returned, then you can
call _query. This is great for inserts, updates and deletes. Calling
this function
bypasses emulated binding, debugging, and recordset handling. Either
the resultid, true or false are returned by _query(). </p><p>For Informix, you can disable scrollable cursors with $db-&gt;cursorType = 0.
</p><p><a name="hack"></a> </p>
<h2>Hacking ADOdb Safely</h2>
<p>You might want to modify ADOdb for your own purposes. Luckily you can
still maintain backward compatibility by sub-classing ADOdb and using the $ADODB_NEWCONNECTION
variable. $ADODB_NEWCONNECTION allows you to override the behaviour of ADONewConnection().
ADOConnection() checks for this variable and will call
the function-name stored in this variable if it is defined.
</p><p>In the following example, new functionality for the connection object 
is placed in the <i>hack_mysql</i> and <i>hack_postgres7</i> classes. The recordset class naming convention
can be controlled using $rsPrefix. Here we set it to 'hack_rs_', which will make ADOdb use
<i>hack_rs_mysql</i> and <i>hack_rs_postgres7</i> as the recordset classes.

</p><pre>class hack_mysql extends adodb_mysql {<br>var $rsPrefix = 'hack_rs_';<br>  /* Your mods here */<br>}<br><br>class hack_rs_mysql extends ADORecordSet_mysql {<br>	 /* Your mods here */<br>}<br><br>class hack_postgres7 extends adodb_postgres7 {<br>var $rsPrefix = 'hack_rs_';<br>  /* Your mods here */<br>}<br><br>class hack_rs_postgres7 extends ADORecordSet_postgres7 {<br> /* Your mods here */<br>}<br><br>$ADODB_NEWCONNECTION = 'hack_factory';<br><br>function&amp; hack_factory($driver)<br>{<br>	if ($driver !== 'mysql' &amp;&amp; $driver !== 'postgres7') return false;<br>	<br>	$driver = 'hack_'.$driver;<br>	$obj = new $driver();<br>	return $obj;<br>}<br><br>include_once('adodb.inc.php');<br></pre>
<p></p><p>Don't forget to call the constructor of the parent class in
your constructor. If you want to use the default ADOdb drivers return
false in the above hack_factory() function.
<a name="php5"></a>
</p><h2>PHP5 Features</h2>
 ADOdb 4.02 or later will transparently determine which version of PHP you are using.
If PHP5 is detected, the following features become available:

<li><b>PDO</b>: PDO drivers are available. See the <a href=#pdo>connection examples</a>. Currently PDO drivers are
 not as powerful as native drivers, and should be treated as experimental.<br><br>
<a name="php5iterators"></a>
<li><b>Foreach iterators</b>: This is a very natural way of going through a recordset:
<pre>	$ADODB_FETCH_MODE = ADODB_FETCH_NUM;<br>	$rs = $db-&gt;Execute($sql);<br>	foreach($rs as $k =&gt; $row) {<br>		echo "r1=".$row[0]." r2=".$row[1]."&lt;br&gt;";<br>	}<br></pre>
<a name="php5exceptions"></a>
</p></li><li><b>Exceptions</b>: Just include <i>adodb-exceptions.inc.php</i> and you can now 
catch exceptions on errors as they occur.
<pre>	<b>include("../adodb-exceptions.inc.php");</b> <br>	include("../adodb.inc.php");	 <br>	try { <br>		$db = NewADOConnection("oci8"); <br>		$db-&gt;Connect('','scott','bad-password'); <br>	} catch (exception $e) { <br>		var_dump($e); <br>		adodb_backtrace($e-&gt;gettrace());<br>	} <br></pre>
<p>Note that reaching EOF is <b>not</b> considered an error nor an exception.
<h3><a name="drivers"></a>Databases Supported</h3>
The <i>name</i> below is the value you pass to NewADOConnection($name) to create a  connection object for that database.
</p><table border="1" width="100%">
  <tbody><tr valign="top"> 
    <td><b><font size="2">RecordCount() usable</font></b></td>
    <td><b>Operating Systems</b></td>
  <tr valign="top"> 
    <td><b><font size="2">access</font></b></td>
    <td><font size="2">B</font></td>
    <td><font size="2">Microsoft Access/Jet. You need to create an ODBC DSN.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ODBC </font></td>
    <td><font size="2">Windows only</font></td>
  <tr valign="top"> 
    <td><b><font size="2">ado</font></b></td>
    <td><font size="2">B</font></td>
    <td><p><font size="2">Generic ADO, not tuned for specific databases. Allows 
        DSN-less connections. For best performance, use an OLEDB provider. This 
        is the base class for all ado drivers.</font></p>
      <p><font size="2">You can set $db-&gt;codePage before connecting.</font></p></td>
    <td><font size="2">? depends on database</font></td>
    <td><font size="2">ADO or OLEDB provider</font></td>
    <td><font size="2">Windows only</font></td>
  <tr valign="top"> 
    <td><b><font size="2">ado_access</font></b></td>
    <td><font size="2">B</font></td>
    <td><font size="2">Microsoft Access/Jet using ADO. Allows DSN-less connections. 
      For best performance, use an OLEDB provider.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ADO or OLEDB provider</font></td>
    <td><font size="2">Windows only</font></td>
  <tr valign="top"> 
    <td><b><font size="2">ado_mssql</font></b></td>
    <td><font size="2">B</font></td>
    <td><font size="2">Microsoft SQL Server using ADO. Allows DSN-less connections. 
      For best performance, use an OLEDB provider.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ADO or OLEDB provider</font></td>
    <td><font size="2">Windows only</font></td>
    <tr valign="top"> 
    <td height="54"><b><font size="2">db2</font></b></td>
    <td height="54"><font size="2">C</font></td>
    <td height="54"><font size="2">Uses PHP's db2-specific extension for better performance.</font></td>
    <td height="54"><font size="2">Y/N</font></td>
    <td height="54"><font size="2">DB2 CLI/ODBC interface</font></td>
    <td height="54"> <p><font size="2">Unix and Windows. Requires IBM DB2 Universal Database client.</font></p></td>
  <tr valign="top"> 
    <td height="54"><b><font size="2">odbc_db2</font></b></td>
    <td height="54"><font size="2">C</font></td>
    <td height="54"><font size="2">Connects to DB2 using generic ODBC extension.</font></td>
    <td height="54"><font size="2">Y/N</font></td>
    <td height="54"><font size="2">DB2 CLI/ODBC interface</font></td>
    <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 
        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>
  <tr valign="top"> 
    <td><b><font size="2">vfp</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">Microsoft Visual FoxPro. You need to create an ODBC DSN.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ODBC</font></td>
    <td><font size="2">Windows only</font></td>
  <tr valign="top"> 
    <td><b><font size="2">fbsql</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">FrontBase. </font></td>
    <td><font size="2">Y</font></td>
    <td><font size="2">?</font></td>
    <td> <p><font size="2">Unix and Windows</font></p></td>
  <tr valign="top"> 
    <td><b><font size="2">ibase</font></b></td>
    <td><font size="2">B</font></td>
    <td><font size="2">Interbase 6 or earlier. Some users report you might need 
      to use this<br>
      $db-&gt;PConnect('localhost:c:/ibase/employee.gdb', "sysdba", "masterkey") 
      to connect. Lacks Affected_Rows currently.<br>
      You can set $db-&gt;role, $db-&gt;dialect, $db-&gt;buffers and $db-&gt;charSet before connecting.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Interbase client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><i><font size="2">firebird</font></i></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Firebird version of interbase.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Interbase client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><i><font size="2">borland_ibase</font></i></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Borland version of Interbase 6.5 or later. Very sad that 
      the forks differ.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Interbase client</font></td>
    <td><font size="2">Unix and Windows</font></td>

  <tr valign="top"> 
    <td><b><font size="2">informix</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Generic informix driver. Use this if you are using Informix 7.3 or later.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Informix client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">informix72</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2"> Informix databases before Informix 7.3 that do no support 
      SELECT FIRST.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Informix client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">ldap</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">LDAP driver. See this example for usage information.</font></td>
    <td><font size="2">LDAP extension</font></td>
    <td><font size="2">?</font></td>
  <tr valign="top"> 
    <td height="73"><b><font size="2">mssql</font></b></td>
    <td height="73"><font size="2">A</font></td>
    <td height="73"> <p><font size="2">Microsoft SQL Server 7 and later. Works 
        with Microsoft SQL Server 2000 also. Note that date formating is problematic 
        with this driver. For example, the PHP mssql extension does not return 
        the seconds for datetime!</font></p></td>
    <td height="73"><font size="2">Y/N</font></td>
    <td height="73"><font size="2">Mssql client</font></td>
    <td height="73"> <p><font size="2">Unix and Windows. <br>
        <a href="http://phpbuilder.com/columns/alberto20000919.php3">Unix install 
        howto</a> and <a href="http://linuxjournal.com/article.php?sid=6636&amp;mode=thread&amp;order=0">another 
        one</a>. </font></p></td>
  <tr valign="top"> 
    <td height="73"><b><font size="2">mssqlpo</font></b></td>
    <td height="73"><font size="2">A</font></td>
    <td height="73"> <p><font size="2">Portable mssql driver. Identical to above 
        mssql driver, except that '||', the concatenation operator, is converted 
        to '+'. Useful for porting scripts from most other sql variants that use 
    <td height="73"><font size="2">Y/N</font></td>
    <td height="73"><font size="2">Mssql client</font></td>
    <td height="73"> <p><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3"><br>
        Unix install howto</a>.</font></p></td>
  <tr valign="top"> 
    <td><b><font size="2">mysql</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">MySQL without transaction support. You can also set $db-&gt;clientFlags 
      before connecting.</font></td>
    <td><font size="2">Y</font></td>
    <td><font size="2">MySQL client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><font size="2"><b>mysqlt</b> or <b>maxsql</b></font></td>
    <td><font size="2">A</font></td>
    <td> <p><font size="2">MySQL with transaction support. We recommend using 
        || as the concat operator for best portability. This can be done by running 
        MySQL using: <br>
        <i>mysqld --ansi</i> or <i>mysqld --sql-mode=PIPES_AS_CONCAT</i></font></p></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">MySQL client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">oci8</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">Oracle 8/9. Has more functionality than <i>oracle</i> driver 
      (eg. Affected_Rows). You might have to putenv('ORACLE_HOME=...') before 
      Connect/PConnect. </font> <p><font size="2"> There are 2 ways of connecting 
        - with server IP and service name: <br>
        or using an entry in TNSNAMES.ORA or ONAMES or HOSTNAMES: <br>
        <i>PConnect(false, 'scott', 'tiger', $oraname)</i>. </font> 
      </p><p><font size="2">Since 2.31, we support Oracle REF cursor variables directly 
        (see <a href="#executecursor">ExecuteCursor</a>).</font> </p></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Oracle client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">oci805</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Supports reduced Oracle functionality for Oracle 8.0.5. 
      SelectLimit is not as efficient as in the oci8 or oci8po drivers.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Oracle client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">oci8po</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">Oracle 8/9 portable driver. This is nearly identical with 
      the oci8 driver except (a) bind variables in Prepare() use the ? convention, 
      instead of :bindvar, (b) field names use the more common PHP convention 
      of lowercase names. </font> <p><font size="2">Use this driver if porting 
        from other databases is important. Otherwise the oci8 driver offers better 
        performance. </font> </p></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Oracle client</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">odbc</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">Generic ODBC, not tuned for specific databases. To connect, 
      use <br>
      PConnect('DSN','user','pwd'). This is the base class for all odbc derived 
    <td><font size="2">? depends on database</font></td>
    <td><font size="2">ODBC</font></td>
    <td><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3?page=4">Unix 
  <tr valign="top"> 
    <td><b><font size="2">odbc_mssql</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Uses ODBC to connect to MSSQL</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ODBC</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">odbc_oracle</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Uses ODBC to connect to Oracle</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">ODBC</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">odbtp</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Generic odbtp driver. <a href="http://odbtp.sourceforge.net/">Odbtp</a> is a software for
	accessing Windows ODBC data sources from other operating systems.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">odbtp</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td><b><font size="2">odbtp_unicode</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Odtbp with unicode support</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">odbtp</font></td>
    <td><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td height="34"><b><font size="2">oracle</font></b></td>
    <td height="34"><font size="2">C</font></td>
    <td height="34"><font size="2">Implements old Oracle 7 client API. Use oci8 
      driver if possible for better performance.</font></td>
    <td height="34"><font size="2">Y/N</font></td>
    <td height="34"><font size="2">Oracle client</font></td>
    <td height="34"><font size="2">Unix and Windows</font></td>
  <tr valign="top"> 
    <td height="34"><b><font size="2">netezza</font></b></td>
    <td height="34"><font size="2">C</font></td>
    <td height="34"><font size="2">Netezza driver. Netezza is based on postgres code-base.</font></td>
    <td height="34"><font size="2">Y</font></td>
    <td height="34"><font size="2">?</font></td>
    <td height="34"><font size="2">?</font></td>
     <tr valign="top"> 
    <td><b><font size="2">pdo</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Generic PDO driver for PHP5. </font></td>
    <td><font size="2">Y</font></td>
    <td><font size="2">PDO extension and database specific drivers</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">postgres</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">Generic PostgreSQL driver. Currently identical to postgres7 
    <td><font size="2">Y</font></td>
    <td><font size="2">PostgreSQL client</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">postgres64</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">For PostgreSQL 6.4 and earlier which does not support LIMIT 
    <td><font size="2">Y</font></td>
    <td><font size="2">PostgreSQL client</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">postgres7</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">PostgreSQL which supports LIMIT and other version 7 functionality.</font></td>
    <td><font size="2">Y</font></td>
    <td><font size="2">PostgreSQL client</font></td>
    <td><font size="2">Unix and Windows. </font></td>
    <tr valign="top"> 
    <td><b><font size="2">postgres8</font></b></td>
    <td><font size="2">A</font></td>
    <td><font size="2">PostgreSQL which supports version 8 functionality.</font></td>
    <td><font size="2">Y</font></td>
    <td><font size="2">PostgreSQL client</font></td>
    <td><font size="2">Unix and Windows. </font></td>
  <tr valign="top"> 
    <td><b><font size="2">sapdb</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">SAP DB. Should work reliably as based on ODBC driver.</font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">SAP ODBC client</font></td>
    <td> <p><font size="2">?</font></p></td>
  <tr valign="top"> 
    <td><b><font size="2">sqlanywhere</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Sybase SQL Anywhere. Should work reliably as based on ODBC 
    <td><font size="2">Y/N</font></td>
    <td><font size="2">SQL Anywhere ODBC client</font></td>
    <td> <p><font size="2">?</font></p></td>
  <tr valign="top"> 
    <td height="54"><b><font size="2">sqlite</font></b></td>
    <td height="54"><font size="2">B</font></td>
    <td height="54"><font size="2">SQLite.</font></td>
    <td height="54"><font size="2">Y</font></td>
    <td height="54"><font size="2">-</font></td>
    <td height="54"> <p><font size="2">Unix and Windows.</font></p></td>
    <tr valign="top"> 
    <td height="54"><b><font size="2">sqlitepo</font></b></td>
    <td height="54"><font size="2">B</font></td>
    <td height="54"><font size="2">Portable SQLite driver.  This is because assoc mode does not work like other drivers in sqlite.
   Namely, when selecting (joining) multiple tables, the table
   	  names are included in the assoc keys in the "sqlite" driver.</font><p>
<font size="2">	  In "sqlitepo" driver, the table names are stripped from the returned column names. 
	  When this results in a conflict,  the first field get preference.
    <td height="54"><font size="2">Y</font></td>
    <td height="54"><font size="2">-</font></td>
    <td height="54"> <p><font size="2">Unix and Windows.</font></p></td>
  <tr valign="top"> 
    <td><b><font size="2">sybase</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Sybase. </font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Sybase client</font></td>
    <td> <p><font size="2">Unix and Windows.</font></p></td>
    <tr valign="top"> 
    <td><b><font size="2">sybase_ase</font></b></td>
    <td><font size="2">C</font></td>
    <td><font size="2">Sybase ASE. </font></td>
    <td><font size="2">Y/N</font></td>
    <td><font size="2">Sybase client</font></td>
    <td> <p><font size="2">Unix and Windows.</font></p></td>

<p></p><p>The "Tested" column indicates how extensively the code has been tested 
  and used. <br>
  A = well tested and used by many people<br>
  B = tested and usable, but some features might not be implemented<br>
  C = user contributed or experimental driver. Might not fully support all of 
  the latest features of ADOdb. </p>
<p>The column "RecordCount() usable" indicates whether RecordCount() 
  return the number of rows, or returns -1 when a SELECT statement is executed. 
  If this column displays Y/N then the RecordCount() is emulated when the global 
  variable $ADODB_COUNTRECS=true (this is the default). Note that for large recordsets, 
  it might be better to disable RecordCount() emulation because substantial amounts 
  of memory are required to cache the recordset for counting. Also there is a 
  speed penalty of 40-50% if emulation is required. This is emulated in most databases 
  except for PostgreSQL and MySQL. This variable is checked every time a query 
  is executed, so you can selectively choose which recordsets to count.</p>
</p><hr />
<h1>Tutorials<a name="quickstart"></a></h1>
<h3>Example 1: Select Statement<a name="ex1"></a></h3>
<p>Task: Connect to the Access Northwind DSN, display the first 2 columns of each 
<p>In this example, we create a ADOConnection object, which represents the connection 
  to the database. The connection is initiated with <a href="#pconnect"><font face="Courier New, Courier, mono">PConnect</font></a>, 
  which is a persistent connection. Whenever we want to query the database, we 
  call the <font face="Courier New, Courier, mono">ADOConnection.<a href="#execute">Execute</a>()</font> 
  function. This returns an ADORecordSet object which is actually a cursor that 
  holds the current row in the array <font face="Courier New, Courier, mono">fields[]</font>. 
  We use <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font> 
  to move from row to row.</p>
<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>, 
  which allows us to limit the number of rows shown. 
</p><pre>&lt;?<br><font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php');	   # load code common to ADOdb<br>$<font color="#660000">conn</font> = &amp;ADONewConnection('access');	# create a connection<br>$<font color="#660000">conn</font>-&gt;PConnect('northwind');   # connect to MS-Access, northwind DSN<br>$<font color="#660000">recordSet</font> = &amp;$<font color="#660000">conn</font>-&gt;Execute('select * from products');<br>if (!$<font color="#660000">recordSet</font>) <br>	print $<font color="#660000">conn</font>-&gt;ErrorMsg();<br>else<br><b>while</b> (!$<font color="#660000">recordSet</font>-&gt;EOF) {<br>	<b>print</b> $<font color="#660000">recordSet</font>-&gt;fields[0].' '.$<font color="#660000">recordSet</font>-&gt;fields[1].'&lt;BR&gt;';<br>	$<font color="#660000">recordSet</font>-&gt;MoveNext();<br>}</font><font face="Courier New, Courier, mono">

$<font color="#660000">recordSet</font>-&gt;Close(); # optional<br>$<font color="#660000">conn</font>-&gt;Close(); # optional<br></font>
<p>The $<font face="Courier New, Courier, mono">recordSet</font> returned stores 
  the current row in the <font face="Courier New, Courier, mono">$recordSet-&gt;fields</font> 
  array, indexed by column number (starting from zero). We use the <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font> 
  function to move to the next row. The <font face="Courier New, Courier, mono">EOF</font> 
  property is set to true when end-of-file is reached. If an error occurs in Execute(), 
  we return false instead of a recordset.</p>
<p>The <code>$recordSet-&gt;fields[]</code> array is generated by the PHP database 
  extension. Some database extensions only index by number and do not index the 
  array by field name. To force indexing by name - that is associative arrays 
  - use the SetFetchMode function. Each recordset saves and uses whatever fetch 
  mode was set when the recordset was created in Execute() or SelectLimit(). 
</p><pre>	$db-&gt;SetFetchMode(ADODB_FETCH_NUM);<br>	$rs1 = $db-&gt;Execute('select * from table');<br>	$db-&gt;SetFetchMode(ADODB_FETCH_ASSOC);<br>	$rs2 = $db-&gt;Execute('select * from table');<br>	print_r($rs1-&gt;fields); # shows <i>array([0]=&gt;'v0',[1] =&gt;'v1')</i>
	print_r($rs2-&gt;fields); # shows <i>array(['col1']=&gt;'v0',['col2'] =&gt;'v1')</i>
<p> </p>
<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>. 
  Note that it can return -1 if the number of rows returned cannot be determined.</p>
<h3>Example 2: Advanced Select with Field Objects<a name="ex2"></a></h3>
<p>Select a table, display the first two columns. If the second column is a date 
  or timestamp, reformat the date to US format.</p>
<pre>&lt;?<br><font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php');	   # load code common to ADOdb<br>$<font color="#660000">conn</font> = &amp;ADONewConnection('access');	# create a connection<br>$<font color="#660000">conn</font>-&gt;PConnect('northwind');   # connect to MS-Access, northwind dsn<br>$<font color="#660000">recordSet</font> = &amp;$<font color="#660000">conn</font>-&gt;Execute('select CustomerID,OrderDate from Orders');<br>if (!$<font color="#660000">recordSet</font>) <br>	print $<font color="#660000">conn</font>-&gt;ErrorMsg();<br>else<br><b>while</b> (!$<font color="#660000">recordSet</font>-&gt;EOF) {<br>	$<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>
	$<font color="#660000">type</font> = <font color="#336600"><b>$</b><font color="#660000">recordSet</font><b>-&gt;MetaType</b></font>($fld-&gt;type);<br><br>	<b>if</b> ( $<font color="#660000">type</font> == 'D' || $<font color="#660000">type</font> == 'T') <br>		<b>print</b> $<font color="#660000">recordSet</font>-&gt;fields[0].' '.<br>			<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;';<br>	<b>else </b>
		<b>print</b> $<font color="#660000">recordSet</font>-&gt;fields[0].' '.$<font color="#660000">recordSet</font>-&gt;fields[1].'&lt;BR&gt;';<br><br>	$<font color="#660000">recordSet</font>-&gt;MoveNext();<br>}</font><font face="Courier New, Courier, mono">
$<font color="#660000">recordSet</font>-&gt;Close(); # optional<br>$<font color="#660000">conn</font>-&gt;Close(); # optional<br></font>
<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> 
  This returns an object with at least 3 fields.</p>
  <li><b>name</b>: name of column</li>
  <li> <b>type</b>: native field type of column</li>
  <li> <b>max_length</b>: maximum length of field. Some databases such as MySQL 
    do not return the maximum length of the field correctly. In these cases max_length 
    will be set to -1.</li>
<p>We then use <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font> 
  to translate the native type to a <i>generic</i> type. Currently the following 
  <i>generic</i> types are defined:</p>
  <li><b>C</b>: character fields that should be shown in a &lt;input type="text"&gt; 
  <li><b>X</b>: TeXt, large text fields that should be shown in a &lt;textarea&gt;</li>
  <li><b>B</b>: Blobs, or Binary Large Objects. Typically images. 
  </li><li><b>D</b>: Date field</li>
  <li><b>T</b>: Timestamp field</li>
  <li><b>L</b>: Logical field (boolean or bit-field)</li>
  <li><b>I</b>:&nbsp; Integer field</li>
  <li><b>N</b>: Numeric field. Includes autoincrement, numeric, floating point, 
    real and integer. </li>
  <li><b>R</b>: Serial field. Includes serial, autoincrement integers. This works 
    for selected databases. </li>
<p>If the metatype is of type date or timestamp, then we print it using the user 
  defined date format with <font face="Courier New, Courier, mono"><a href="#userdate">UserDate</a>(),</font> 
  which converts the PHP SQL date string format to a user defined one. Another 
  use for <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font> 
  is data validation before doing an SQL insert or update.</p>
<h3>Example 3: Inserting<a name="ex3"></a></h3>
<p>Insert a row to the Orders table containing dates and strings that need to 
  be quoted before they can be accepted by the database, eg: the single-quote 
  in the word <i>John's</i>.</p>
<pre>&lt;?<br><b>include</b>('adodb.inc.php');	   # load code common to ADOdb<br>$<font color="#660000">conn</font> = &amp;ADONewConnection('access');	# create a connection<br><br>$<font color="#660000">conn</font>-&gt;PConnect('northwind');   # connect to MS-Access, northwind dsn<br>$<font color="#660000">shipto</font> = <font color="#006600"><b>$conn-&gt;qstr</b></font>("<i>John's Old Shoppe</i>");<br><br>$<font color="#660000">sql</font> = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";<br>$<font color="#660000">sql</font> .= "values ('ANATR',2,".<b><font color="#006600">$conn-&gt;DBDate(</font>time()<font color="#006600">)</font></b><font color="#006600">.</font>",$<font color="#660000">shipto</font>)";<br><br><b>if</b> ($<font color="#660000">conn</font>-&gt;Execute($<font color="#660000">sql</font>) <font color="#336600"><b>=== false</b></font>) {<br>	<b>print</b> 'error inserting: '.<font color="#336600"><b>$conn-&gt;ErrorMsg()</b></font>.'&lt;BR&gt;';<br>}<br>?&gt;<br></pre>
<p>In this example, we see the advanced date and quote handling facilities of 
  ADOdb. The unix timestamp (which is a long integer) is appropriately formated 
  for Access with <font face="Courier New, Courier, mono"><a href="#dbdate">DBDate</a>()</font>, 
  and the right escape character is used for quoting the <i>John's Old Shoppe</i>, 
  which is<b> </b><i>John'<b>'</b>s Old Shoppe</i> and not PHP's default <i>John<b>'</b>s 
  Old Shoppe</i> with <font face="Courier New, Courier, mono"><a href="#qstr">qstr</a>()</font>. 
<p>Observe the error-handling of the Execute statement. False is returned by<font face="Courier New, Courier, mono"> 
  <a href="#execute">Execute</a>() </font>if an error occured. The error message 
  for the last error that occurred is displayed in <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font>. 
  Note: <i>php_track_errors</i> might have to be enabled for error messages to 
  be saved.</p>
<h3> Example 4: Debugging<a name="ex4"></a></h3>
<pre>&lt;?<br><b>include</b>('adodb.inc.php');	   # load code common to ADOdb<br>$<font color="#663300">conn</font> = &amp;ADONewConnection('access');	# create a connection<br>$<font color="#663300">conn</font>-&gt;PConnect('northwind');   # connect to MS-Access, northwind dsn<br><font>$<font color="#663300">shipto</font> = <b>$conn-&gt;qstr</b>("John's Old Shoppe");<br>$<font color="#663300">sql</font> = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";<br>$<font color="#663300">sql</font> .= "values ('ANATR',2,".$<font color="#663300">conn</font>-&gt;FormatDate(time()).",$shipto)";<br><b><font color="#336600">$<font color="#663300">conn</font>-&gt;debug = true;</font></b>
<b>if</b> ($<font color="#663300">conn</font>-&gt;Execute($sql) <b>=== false</b>) <b>print</b> 'error inserting';</font>
<p>In the above example, we have turned on debugging by setting <b>debug = true</b>. 
  This will display the SQL statement before execution, and also show any error 
  messages. There is no need to call <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font> 
  in this case. For displaying the recordset, see the <font face="Courier New, Courier, mono"><a href="#exrs2html">rs2html</a>() 
<p>Also see the section on <a href="#errorhandling">Custom Error Handlers</a>.</p>
<h3>Example 5: MySQL and Menus<a name="ex5"></a></h3>
<p>Connect to MySQL database <i>agora</i>, and generate a &lt;select&gt; menu 
  from an SQL statement where the &lt;option&gt; captions are in the 1st column, 
  and the value to send back to the server is in the 2nd column.</p>
<pre>&lt;?<br><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#663300">conn</font> = &amp;ADONewConnection('mysql');  # create a connection<br>$<font color="#663300">conn</font>-&gt;PConnect('localhost','userid','','agora');# connect to MySQL, agora db<br><font>$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';<br>$<font color="#663300">rs</font> = $<font color="#663300">conn</font>-&gt;Execute($sql);<br><b>print</b> <b><font color="#336600">$<font color="#663300">rs</font>-&gt;GetMenu('GetCust','Mary Rosli');<br>?&gt;</font></b></font></pre>
<p>Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected. 
  See <a href="#getmenu"><font face="Courier New, Courier, mono">GetMenu</font></a><font face="Courier New, Courier, mono">()</font>. 
  We also have functions that return the recordset as an array: <font face="Courier New, Courier, mono"><a href="#getarray">GetArray</a>()</font>, 
  and as an associative array with the key being the first column: <a href="#getassoc1">GetAssoc</a>().</p>
<h3>Example 6: Connecting to 2 Databases At Once<a name="ex6"></a></h3>
<pre>&lt;?<br><b>include</b>('adodb.inc.php');	 # load code common to ADOdb<br>$<font color="#663300">conn1</font> = &amp;ADONewConnection('mysql');  # create a mysql connection<br>$<font color="#663300">conn2</font> = &amp;ADONewConnection('oracle');  # create a oracle connection<br><br>$conn1-&gt;PConnect($server, $userid, $password, $database);<br>$conn2-&gt;PConnect(false, $ora_userid, $ora_pwd, $oraname);<br><br>$conn1-&gt;Execute('insert ...');<br>$conn2-&gt;Execute('update ...');<br>?&gt;</pre>
</p><h3>Example 7: Generating Update and Insert SQL<a name="ex7"></a></h3>
<p>Since ADOdb 4.56, we support <a href="reference.functions.getupdatesql.html#autoexecute">AutoExecute()</a>, 
which simplifies things by providing an advanced wrapper for GetInsertSQL() and GetUpdateSQL(). For example,
an INSERT can be carried out with:

    $record["firstname"] = "Bob"; 
    $record["lastname"] = "Smith"; 
    $record["created"] = time(); 
    $insertSQL = $conn->AutoExecute($rs, $record, 'INSERT'); 

and an UPDATE with:
    $record["firstname"] = "Caroline"; 
    $record["lastname"] = "Smith"; # Update Caroline's lastname from Miranda to Smith 
    $insertSQL = $conn->AutoExecute($rs, $record, 'UPDATE', 'id = 1'); 
The rest of this section is out-of-date:
<p>ADOdb 1.31 and later supports two new recordset functions: GetUpdateSQL( ) and 
GetInsertSQL( ). This allow you to perform a "SELECT * FROM table query WHERE...", 
make a copy of the $rs-&gt;fields, modify the fields, and then generate the SQL to 
update or insert into the table automatically. 
<p> We show how the functions can be used when accessing a table with the following 
  fields: (ID, FirstName, LastName, Created). 
</p><p> Before these functions can be called, you need to initialize the recordset 
  by performing a select on the table. Idea and code by Jonathan Younger jyounger#unilab.com. 
 Since ADOdb 2.42, you can pass a  table name instead of a recordset into 
GetInsertSQL (in $rs), and it will generate an insert statement for that table.
</p><pre>&lt;?<br>#==============================================<br># SAMPLE GetUpdateSQL() and GetInsertSQL() code<br>#==============================================<br>include('adodb.inc.php');<br>include('tohtml.inc.php');<br><br>#==========================<br># This code tests an insert<br><br>$sql = "SELECT * FROM ADOXYZ WHERE id = -1"; <br># Select an empty record from the database<br><br>$conn = &amp;ADONewConnection("mysql");  # create a connection<br>$conn-&gt;debug=1;<br>$conn-&gt;PConnect("localhost", "admin", "", "test"); # connect to MySQL, testdb<br>$rs = $conn-&gt;Execute($sql); # Execute the query and get the empty recordset<br><br>$record = array(); # Initialize an array to hold the record data to insert<br><br># Set the values for the fields in the record<br># Note that field names are case-insensitive<br>$record["firstname"] = "Bob";<br>$record["lastNamE"] = "Smith";<br>$record["creaTed"] = time();<br><br># Pass the empty recordset and the array containing the data to insert<br># into the GetInsertSQL function. The function will process the data and return<br># a fully formatted insert sql statement.<br>$insertSQL = $conn-&gt;GetInsertSQL($rs, $record);<br><br>$conn-&gt;Execute($insertSQL); # Insert the record into the database<br><br>#==========================<br># This code tests an update<br><br>$sql = "SELECT * FROM ADOXYZ WHERE id = 1"; <br># Select a record to update<br><br>$rs = $conn-&gt;Execute($sql); # Execute the query and get the existing record to update<br><br>$record = array(); # Initialize an array to hold the record data to update<br><br># Set the values for the fields in the record<br># Note that field names are case-insensitive<br>$record["firstname"] = "Caroline";<br>$record["LasTnAme"] = "Smith"; # Update Caroline's lastname from Miranda to Smith<br><br># Pass the single record recordset and the array containing the data to update<br># into the GetUpdateSQL function. The function will process the data and return<br># a fully formatted update sql statement with the correct WHERE clause.<br># If the data has not changed, no recordset is returned<br>$updateSQL = $conn-&gt;GetUpdateSQL($rs, $record);<br><br>$conn-&gt;Execute($updateSQL); # Update the record in the database<br>$conn-&gt;Close();<br>?&gt;<br></pre>
<a name="ADODB_FORCE_TYPE"></a>
The behaviour of AutoExecute(), GetUpdateSQL() and GetInsertSQL()  
when converting empty or null PHP variables to SQL is controlled by the
 global $ADODB_FORCE_TYPE variable. Set it to one of the values below. Default
</p><pre>0 = ignore empty fields. All empty fields in array are ignored.<br>1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values.<br>2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values.<br>3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and <br>    empty fields '' are set to empty '' sql values.<br><br>define('ADODB_FORCE_IGNORE',0);<br>define('ADODB_FORCE_NULL',1);<br>define('ADODB_FORCE_EMPTY',2);<br>define('ADODB_FORCE_VALUE',3);<br></pre>
Thanks to Niko (nuko#mbnet.fi) for the $ADODB_FORCE_TYPE code.
Note: the constant ADODB_FORCE_NULLS is obsolete since 4.52 and is ignored. Set $ADODB_FORCE_TYPE = ADODB_FORCE_NULL
for equivalent behaviour.
<p>Since 4.62, the table name to be used can be overridden by setting $rs->tableName before AutoExecute(), GetInsertSQL() or GetUpdateSQL() is called.
</p><h3>Example 8: Implementing Scrolling with Next and Previous<a name="ex8"></a></h3>
<p> The following code creates a very simple recordset pager, where you can scroll 
  from page to page of a recordset.</p>
<pre>include_once('../adodb.inc.php');<br>include_once('../adodb-pager.inc.php');<br>session_start();<br><br>$db = NewADOConnection('mysql');<br><br>$db-&gt;Connect('localhost','root','','xphplens');<br><br>$sql = "select * from adoxyz ";<br><br>$pager = new ADODB_Pager($db,$sql);<br>$pager-&gt;Render($rows_per_page=5);</pre>
<p>This will create a basic record pager that looks like this: <a name="scr"></a> 
<table bgcolor="beige" border="1">
    <td> <a href="#scr"><code>|&lt;</code></a> &nbsp; <a href="#scr"><code>&lt;&lt;</code></a> 
      &nbsp; <a href="#scr"><code>&gt;&gt;</code></a> &nbsp; <a href="#scr"><code>&gt;|</code></a> 
      &nbsp; </td>
    <td><table bgcolor="white" border="1" cols="4" width="100%">
        <th>First Name</th>
        <th>Last Name</th>
        <th>Date Created</th>
          <td align="right">36&nbsp;</td>
          <td>Sat 06, Oct 2001&nbsp;</td>
          <td align="right">37&nbsp;</td>
          <td>Sat 06, Oct 2001&nbsp;</td>
          <td align="right">38&nbsp;</td>
          <td>Yat Sun&nbsp;</td>
          <td>Sat 06, Oct 2001&nbsp;</td>
          <td align="right">39&nbsp;</td>
          <td>Wai Hun&nbsp;</td>
          <td>Sat 06, Oct 2001&nbsp;</td>
          <td align="right">40&nbsp;</td>
          <td>Sat 06, Oct 2001&nbsp;</td>
    <td><font size="-1">Page 8/10</font></td>
</p><p>The number of rows to display at one time is controled by the Render($rows) 
  method. If you do not pass any value to Render(), ADODB_Pager will default to 
  10 records per page. 
</p><p>You can control the column titles by modifying your SQL (supported by most 
</p><pre>$sql = 'select id as "ID", firstname as "First Name", <br>		  lastname as "Last Name", created as "Date Created" <br>		from adoxyz';</pre>
<p>The above code can be found in the <i>adodb/tests/testpaging.php</i> example 
  included with this release, and the class ADODB_Pager in <i>adodb/adodb-pager.inc.php</i>. 
  The ADODB_Pager code can be adapted by a programmer so that the text links can 
  be replaced by images, and the dull white background be replaced with more interesting 
</p><p>You can also allow display of html by setting $pager-&gt;htmlSpecialChars = false. 
</p><p>Some of the code used here was contributed by Iv&aacute;n Oliva and Cornel 
  G. </p>
<h3><a name="ex9"></a>Example 9: Exporting in CSV or Tab-Delimited Format</h3>
<p>We provide some helper functions to export in comma-separated-value (CSV) and 
  tab-delimited formats:</p>
$db = &amp;NewADOConnection('mysql');<br>$db-&gt;Connect($server, $userid, $password, $database);<br><br>$rs = $db-&gt;Execute('select fname as "First Name", surname as "Surname" from table');<br><br>print "&lt;pre&gt;";<br>print <b>rs2csv</b>($rs); # return a string, CSV format<p>print '&lt;hr&gt;';<br><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<br>						 # 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)<br>print "&lt;/pre&gt;";<br><br>$rs-&gt;MoveFirst();<br>$fp = fopen($path, "w");<br>if ($fp) {<br>  <b>rs2csvfile</b>($rs, $fp); # write to file (there is also an rs2tabfile function)<br>  fclose($fp);<br>}<br></pre>
<p> Carriage-returns or newlines are converted to spaces. Field names are returned 
  in the first line of text. Strings containing the delimiter character are quoted 
  with double-quotes. Double-quotes are double-quoted again. This conforms to 
  Excel import and export guide-lines. 
</p><p>All the above functions take as an optional last parameter, $addtitles which 
  defaults to <i>true</i>. When set to <i>false</i> field names in the first line 
  are suppressed. <br>
</p><h3>Example 10: Recordset Filters<a name="ex10"></a></h3>
<p>Sometimes we want to pre-process all rows in a recordset before we use it. 
  For example, we want to ucwords all text in recordset. 
</p><pre>include_once('adodb/rsfilter.inc.php');<br>include_once('adodb/adodb.inc.php');<br><br>// ucwords() every element in the recordset<br>function do_ucwords(&amp;$arr,$rs)<br>{<br>	foreach($arr as $k =&gt; $v) {<br>		$arr[$k] = ucwords($v);<br>	}<br>}<br><br>$db = NewADOConnection('mysql');<br>$db-&gt;PConnect('server','user','pwd','db');<br><br>$rs = $db-&gt;Execute('select ... from table');<br>$rs = <b>RSFilter</b>($rs,'do_ucwords');<br></pre>
<p>The <i>RSFilter</i> function takes 2 parameters, the recordset, and the name 
  of the <i>filter</i> function. It returns the processed recordset scrolled to 
  the first record. The <i>filter</i> function takes two parameters, the current 
  row as an array, and the recordset object. For future compatibility, you should 
  not use the original recordset object. </p>
<h3>Example 11:<a name="ex11"></a> Smart Transactions</h3>
The old way of doing transactions required you to use 
<pre>$conn-&gt;<b>BeginTrans</b>();<br>$ok = $conn-&gt;Execute($sql);<br>if ($ok) $ok = $conn-&gt;Execute($sql2);<br>if (!$ok) $conn-&gt;<b>RollbackTrans</b>();<br>else $conn-&gt;<b>CommitTrans</b>();<br></pre>
This is very complicated for large projects because you have to track the error 
status. Smart Transactions is much simpler. You start a smart transaction by calling 
CompleteTrans() detects when an SQL error occurs, and will Rollback/Commit as 
appropriate. To specificly force a rollback even if no error occured, use FailTrans(). 
Note that the rollback is d