Modules 

  How to create an ADOdb Lite Database Specific 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 Mysql 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.
*
* mysql_example_EXTENDER renamed to mysql_blob_EXTENDER
* mysql_example_ADOConnection renamed to mysql_blob_ADOConnection
* mysql_example_resultset_EXTENDER renamed to mysql_blob_resultset_EXTENDER
* mysql_example_ResultSet renamed to mysql_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 mysql_example_EXTENDER extends '. $last_module . '_ADOConnection { }');

class mysql_example_ADOConnection extends mysql_example_EXTENDER
{
}

eval('class mysql_example_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');

class mysql_example_ResultSet extends mysql_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 mysql_example_module.inc into your favorite editor and change all of the example words to test.

Example:

<?
eval('class mysql_test_EXTENDER extends '. $last_module . '_ADOConnection { }');

class mysql_test_ADOConnection extends mysql_test_EXTENDER
{
}

eval('class mysql_test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');

class mysql_test_ResultSet extends mysql_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 mysql_test_EXTENDER extends '. $last_module . '_ADOConnection { }');

class mysql_test_ADOConnection extends mysql_test_EXTENDER
{
    
function ADOdb_Date()
    {
        
return date("F j, Y, g:i a");
    }
}

eval('class mysql_test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');

class mysql_test_ResultSet extends mysql_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 mysql_test_EXTENDER extends '. $last_module . '_ADOConnection { }');

class mysql_test_ADOConnection extends mysql_test_EXTENDER
{
    
function ADOdb_Date()
    {
        
return date("F j, Y, g:i a");
    }
}

eval('class mysql_test_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');

class mysql_test_ResultSet extends mysql_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.

 

  How to create an ADOdb Lite Generic Module

There is really no difference in creating a generic module except for the class naming. You do not add the database type to the class name.

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
{
}

?>


As you can see it is virtually identical to a database specific module except for the missing database type prepending the class name. The module is then stored in the generic_modules directory and can be used by any database driver.


Copyright ©2005, 2006 Mark Dickenson