How to create an ADOdb Lite Module
You will find a file called example_module.inc in the documentation directory. You should use this file as a base for creating your own module. The content of the file is displayed below.
<?
/**
* ADOdb Lite Example Module
*
* This example module can be used to create your own extention to ADOdb Lite.
*
* The module prefix name and class prefix name should all be the same and lowercase.
* If the new module name is 'blob' then rename this file to 'blob_module.inc'. Rename
* the following class designators.
*
* example_EXTENDER renamed to blob_EXTENDER
* example_ADOConnection renamed to blob_ADOConnection
* example_resultset_EXTENDER renamed to blob_resultset_EXTENDER
* example_ResultSet renamed to blob_ResultSet
*
* Functions that interact with the database should be placed inside the
* blob_ADOConnection class. These are functions accessed using
* $db->function().
*
* Functions that interact with the resetset created by a query should
* be placed inside the blob_ResultSet class. These are functions accessed using
* $result->function().
*
* Example:
* $result = $db->Execute($sql);
* echo $result->function();
*
* Place the file into the approriate database driver directory. You should create one
* for each database you would like to support.
*
* To use your blob module start ADOdb Lite using.
*
* $db = ADONewConnection($databasetype, 'blob');
*
*/
eval('class example_EXTENDER extends '. $last_module . '_ADOConnection { }');
class example_ADOConnection extends example_EXTENDER
{
}
eval('class example_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
class example_ResultSet extends example_resultset_EXTENDER
{
}
?> |
Creating a new module for ADOdb Lite is really quite simple and easy. The hardest thing is deciding what you are going to call your module.
Let's create a module called test. Load the example_module.inc into your favorite editor and change all of the example words to test.
Example:
<?
eval('class test_EXTENDER extends '. $last_module . '_ADOConnection { }');
class test_ADOConnection extends test_EXTENDER
{
}
eval('class test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
class test_ResultSet extends test_resultset_EXTENDER
{
}
?> |
With these changes your new module will be easily added to the ADOConnection class when called.
Now let's add a new function to ADOConnection class to get the current server date.
<?
eval('class test_EXTENDER extends '. $last_module . '_ADOConnection { }');
class test_ADOConnection extends test_EXTENDER
{
function ADOdb_Date()
{
return date("F j, Y, g:i a");
}
}
eval('class test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
class test_ResultSet extends test_resultset_EXTENDER
{
}
?> |
Now lets add a new function to the Resultset class to get the current row/record number that is being retrieved with the Fetch function.
<?
eval('class test_EXTENDER extends '. $last_module . '_ADOConnection { }');
class test_ADOConnection extends test_EXTENDER
{
function ADOdb_Date()
{
return date("F j, Y, g:i a");
}
}
eval('class test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
class test_ResultSet extends test_resultset_EXTENDER
{
function CurrentRow()
{
return $this->_currentRow;
}
}
?> |
Now save the file as test_module.inc to the mysql directory so we can test it. Just add 'test' to the ADONewConnection for the module to be loaded.
$db = ADONewConnection('mysql', 'test');
|
You can then use similar commands as the following to access the current row and date.
$date = $db->ADOdbDate();
$result = $db->Execute($sql);
$currentrow = $result->CurrentRow();
|
If you would like your module to be availible for every driver you must copy it to every driver directory.
|