Location: PHPKode > projects > MembersGear > membersgear/includes/phpgrid/activeDBLib/manual.html
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>activeDBLib Manual</title>
<style type="text/css">
<!--
body {font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 11px; text-align: center; font-weight: normal;}
a {text-decoration: underline; color: #003F80;	text-align: center; font-size: 14px; }
a:hover {text-decoration: none; color: #3163CE; }
.normal {font-size: 12px; text-align: justify; font-weight: normal;}
.small {font-size: 10px}
.header {font-size: 20px; font-weight: bold;}
.subheader {font-size: 14px; font-weight: bold; color: #000099; text-align: left; background-color: #eeeeee;}
.method {font-family: "Courier New", Courier, mono; font-size: 14px; font-weight: bold; color: #000099; text-align: left;}
.code { font-family: "Courier New", Courier, mono; font-size: 13px; font-weight: bold; color: #000099; text-align: left}
.codetable { font-family: "Courier New", Courier, mono; font-size: 12px; font-weight: normal; color: #000099; text-align: left; background-color: #eeeeee;}
-->
</style>
</head>
<body bgcolor="#ffffff">
<p class="normal"><span class="header">activeDBLib Manual v0.1</span>
</p>
<table border="0"><tr><td class="subheader">
What is activeDBLib?
</td></tr>
<tr><td class="normal">
activeDBLib is a PHP class to access MySQL or optionally other databases by using various Database Abstraction Libraries. It's primary intention is to hide the differences between the different Database Abstraction Libraries and to provide standard methods for the database connection, query and result operations. It currently supports the <span class="code">ADODB</span>, the <span class="code">PEAR:DB</span> and the <span class="code">METABASE</span> Library. The only requirement to use one of those Abstraction Libraries is to include the one of your choice in your script. If no Database Abstraction Library is included, the activeDBLib will act as a MySQL wrapper.
</td></tr>
</table>
<br />
<table border="0"><tr><td class="subheader">
Where can activeDBLib be used?
</td></tr>
<tr><td class="normal">
activeDBLib can be used in database based projects to provide the possibility of expanding the database type support without caring about which Database Abstraction Library will be used. So MySQL, Access (ODBC), PostgreSQL, Oracle and other Databases could be accessed by various Database Abstraction Libraries using the same code in your application. You could  easily switch Databases and Database Abstraction Libraries. <u>The project can be this way not only Database independent but also Database Abstraction Library independent.</u>
</td></tr>
</table>
<br />
<table border="0"><tr><td class="subheader">
What can activeDBLib actually do?
</td></tr>
<tr><td class="normal">
activeDBLib does not support all functions of the various Database Abstraction Libraries at the moment (see below). It supports the main functionality though: it connects to the database, sends an SQL query, gets the result as an array, counts the rows (and affected rows) and columns of the operation, gets the column information and handles with errors.
</td></tr>
</table>
<br />
<table border="0"><tr><td class="subheader">
activeDBLib methods overview
</td></tr>
<tr><td class="normal">
<ul>
<li><span class="method">activeDBLib([$driver])</span> -&gt; Class constructor. The parameter $driver sets the database type and is optional. The default value is 'mysql'.</li>
<li><span class="method">debug([$boolean])</span> -&gt; Returns an error message, in case of an error, and exits the application.</li>
<li><span class="method">error()</span> -&gt; Returns an error message, in case of an error, or 'false' and does not exit the application. Call this method whenever you want to catch an error manually.</li>
<li><span class="method">connect([$host,$user,$pass,$dbase,$opt])</span> -&gt; opens a connection to a database server. Use the method parameters as follows: <span class="code">$host</span>: database server host; <span class="code">$user</span>: database user; <span class="code">$pass</span>: database password; <span class="code">$dbase</span>: database name; <span class="code">$opt</span>: additional options (e.g for PEAR:DB and METABASE);</li>
<li><span class="method">pconnect([$host,$user,$pass,$dbase,$opt])</span> -&gt; opens a persistent connection to a database server. Use the method parameters as follows: <span class="code">$host</span>: database server host; <span class="code">$user</span>: database user; <span class="code">$pass</span>: database password; <span class="code">$dbase</span>: database name; <span class="code">$opt</span>: additional options (e.g for PEAR:DB and METABASE);</li>
<li><span class="method">execute($sql)</span> -&gt; sends an SQL query to database</li>
<li><span class="method">getArray()</span> -&gt; fetches a result row as an array.</li>
<li><span class="method">rowCount()</span> -&gt; returns the number of rows in previous operation.</li>
<li><span class="method">fieldCount()</span> -&gt; returns the number of columns in previous operation.</li>
<li><span class="method">affectedRows()</span> -&gt; returns the number of affected rows in previous operation.</li>
<li><span class="method">getField($column, $mode)</span> -&gt; returns information about a column in previous operation. Use the method parameters as follows: <span class="code">$column</span>: the column number; <span class="code">$mode</span>: type of information; accepted values are <span class="code">name</span>: returns the column name; <span class="code">type</span>: returns the column type; <span class="code">max_length</span>: returns the column length; <span class="code">type</span> and <span class="code">max_length</span> are not implemented for <span class="code">METABASE</span> yet.</li>
<li><span class="method">getDBLibrary()</span> -&gt; returns the name of loaded Database Abstraction Library (if any) or activeDBLib.</li>
<li><span class="method">getDriver()</span> -&gt; returns the Database type used (default mysql).</li>
<li><span class="method">htmlTable()</span> -&gt; returns a html table string with the column information and the result rows of a query (test function).</li>
<li><span class="method">disconnect()</span> -&gt; disconnents from database (optional).</li>
</ul>
</td></tr>
</table>
<br />
<table border="0" width="100%"><tr><td class="subheader" colspan="2">
activeDBLib code examples
</td></tr>
<tr><td class="code" colspan="2">
Connect to MySQL
</td></tr>
<tr>
<td class="normal" width="50%">DEFAULT (only MySQL)</td>
<td class="normal" width="50%"> With ADODB</td>
</tr>
<tr>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
$db = new activeDBLib();<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
if ($db->error()) print $db->error();<br />
else print "connected with ".$db->getDBLibrary();<br />
?&gt;
</td>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;adodb.inc.php&quot;);<br />
$db = new activeDBLib();<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
if ($db->error()) print $db->error();<br />
else print "connected with ".$db->getDBLibrary();<br />
?&gt;
</td>
</tr>
<tr>
<td class="normal" width="50%">With PEAR:DB</td>
<td class="normal" width="50%">With METABASE</td>
</tr>
<tr>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;DB.php&quot;);<br />
$db = new activeDBLib();<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
if ($db->error()) print $db->error();<br />
else print "connected with ".$db->getDBLibrary();<br />
?&gt;
</td>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;metabase_interface.php&quot;);<br />
require_once(&quot;metabase_database.php&quot;);<br />
require_once(&quot;metabase_mysql.php&quot;);<br />
$db = new activeDBLib();<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
if ($db->error()) print $db->error();<br />
else print "connected with ".$db->getDBLibrary();<br />
?&gt;
</td>
</tr>
<tr><td class="code" colspan="2">
Connect to MySQL, send an SQL query and display the results in html
</td></tr>
<tr>
<td class="normal" width="50%">DEFAULT (only MySQL)</td>
<td class="normal" width="50%">With ADODB</td>
</tr>
<tr>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
$db = new activeDBLib();<br />
$db->debug(); // catch all errors<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
$db->execute(&quot;SELECT name, telephone FROM clients&quot;);<br />
while ($row = $db->GetArray()){<br />
printf ("Name: %s  Phone: %s&lt;br /&gt;", $row[0], $row[1]);<br />
}<br />
?&gt;
</td>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;adodb.inc.php&quot;);<br />
$db = new activeDBLib();<br />
$db->debug(); // catch all errors<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
$db->execute(&quot;SELECT name, telephone FROM clients&quot;);<br />
while ($row = $db->GetArray()){<br />
printf ("Name: %s  Phone: %s&lt;br /&gt;", $row[0], $row[1]);<br />
}<br />
?&gt;
</td>
</tr>
<tr>
<td class="normal" width="50%">With PEAR:DB</td>
<td class="normal" width="50%">With METABASE</td>
</tr>
<tr>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;DB.php&quot;);<br />
$db = new activeDBLib();<br />
$db->debug(); // catch all errors<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
$db->execute(&quot;SELECT name, telephone FROM clients&quot;);<br />
while ($row = $db->GetArray()){<br />
printf ("Name: %s  Phone: %s&lt;br /&gt;", $row[0], $row[1]);<br />
}<br />
?&gt;
</td>
<td class="codetable" width="50%">
&lt;?php<br />
require_once(&quot;activeDBLib.php&quot;);<br />
require_once(&quot;metabase_interface.php&quot;);<br />
require_once(&quot;metabase_database.php&quot;);<br />
require_once(&quot;metabase_mysql.php&quot;);<br />
$db = new activeDBLib();<br />
$db->debug(); // catch all errors<br />
$db->connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;,&quot;test&quot;);<br />
$db->execute(&quot;SELECT name, telephone FROM clients&quot;);<br />
while ($row = $db->GetArray()){<br />
printf ("Name: %s  Phone: %s&lt;br /&gt;", $row[0], $row[1]);<br />
}<br />
?&gt;
</td>
</tr>
</table>
<br />
<hr></hr>
<table width="100%" border="0" bgcolor="#ffffff">
<tr>
<td class="small">
(c) Giorgos Tsiledakis, Crete Greece
</td>
</tr>
</table>
<hr></hr>
</body>
</html>
Return current item: MembersGear