<b> rs2html($rs)</b>; /* recordset to html table */ </pre>
<p>There are many other helper functions that are listed in the documentation available at <ahref="http://php.weblogs.com/adodb_manual"></a><ahref="http://php.weblogs.com/adodb_manual">http://php.weblogs.com/adodb_manual</a>.
<h2>Advanced Material</h2>
<h3>Inserts and Updates </h3>
<p>Let's say you want to insert the following data into a database.
<p><b>ID</b> = 3<br>
<b>TheDate</b>=mktime(0,0,0,8,31,2001) /* 31st August 2001 */<br>
<b>Note</b>= sugar why don't we call it off
<p>When you move to another database, your insert might no longer work.</p>
<p>The first problem is that each database has a different default date format.
MySQL expects YYYY-MM-DD format, while other databases have different defaults.
ADODB has a function called DBDate() that addresses this issue by converting
converting the date to the correct format.</p>
<p>The next problem is that the <b>don't</b> in the Note needs to be quoted. In
MySQL, we use <b>don\'t</b> but in some other databases (Sybase, Access, Microsoft
SQL Server) we use <b>don''t. </b>The qstr() function addresses this issue.</p>
<p>So how do we use the functions? Like this:</p>
<pre>$sql = "INSERT INTO table (id, thedate,note) values ("
. $<b>ID</b> . ','
. $db->DBDate($<b>TheDate</b>) .','
. $db->qstr($<b>Note</b>).")";
$db->Execute($sql);</pre>
<p>ADODB also supports <code>$connection->Affected_Rows()</code> (returns the
number of rows affected by last update or delete) and <code>$recordset->Insert_ID()</code>
(returns last autoincrement number generated by an insert statement). Be forewarned
that not all databases support the two functions.<br>
</p>
<h3>MetaTypes</h3>
<p>You can find out more information about each of the fields (I use the words
fields and columns interchangebly) you are selecting by calling the recordset
method <code>FetchField($fieldoffset)</code>. This will return an object with
3 properties: name, type and max_length.
<pre>For example:</pre>
<pre>$recordset = $conn->Execute("select adate from table");<br>$f0 = $recordset->FetchField(0);
</pre>
<p>Then <code>$f0->name</code> will hold <i>'adata'</i>, <code>$f0->type</code>
will be set to '<i>date'</i>. If the max_length is unknown, it will be set to
-1.
<p>One problem with handling different databases is that each database often calls
the same type by a different name. For example a <i>timestamp</i> type is called
<i>datetime</i> in one database and <i>time</i> in another. So ADODB has a special
<code>MetaType($type, $max_length)</code> function that standardises the types
to the following:
<p>C: character and varchar types<br>
X: text or long character (eg. more than 255 bytes wide).<br>
B: blob or binary image<br>
D: date<br>
T: timestamp<br>
L: logical (boolean)<br>
I: integer<br>
N: numeric (float, double, money)
<p>In the above date example,
<p><code>$recordset = $conn->Execute("select adate from table");<br>
<p>If you plan to write commercial PHP applications that you want to resell, you should consider ADODB. It has been released using the lesser GPL, which means you can legally include it in commercial applications, while keeping your code proprietary. Commercial use of ADODB is strongly encouraged! We are using it internally for this reason.<p>
<h2>Conclusion</h2>
<p>As a thank you for finishing this article, here are the complete lyrics for
<i>let's call the whole thing off</i>.<br>
<br>
<pre>
Refrain
<br>
You say eether and I say eyether,
You say neether and I say nyther;
Eether, eyether, neether, nyther -
Let's call the whole thing off !
<br>
You like potato and I like po-tah-to,
You like tomato and I like to-mah-to;
Potato, po-tah-to, tomato, to-mah-to -
Let's call the whole thing off !
<br>
But oh, if we call the whole thing off, then we must part.
And oh, if we ever part, then that might break my heart.
<br>
So, if you like pajamas and I like pa-jah-mas,
I'll wear pajamas and give up pa-jah-mas.
For we know we
Need each other, so we
Better call the calling off off.
Let's call the whole thing off !
<br>
Second Refrain
<br>
You say laughter and I say lawfter,
You say after and I say awfter;
Laughter, lawfter, after, awfter -
Let's call the whole thing off !
<br>
You like vanilla and I like vanella,
You, sa's'parilla and I sa's'parella;
Vanilla, vanella, choc'late, strawb'ry -
Let's call the whole thing off !
<br>
But oh, if we call the whole thing off, then we must part.
And oh, if we ever part, then that might break my heart.
<br>
So, if you go for oysters and I go for ersters,
I'll order oysters and cancel the ersters.
For we know we
Need each other, so we
Better call the calling off off.
Let's call the whole thing off !
</pre>
<p><fontsize=2>Song and lyrics by George and Ira Gershwin, introduced by Fred Astaire and Ginger Rogers