In recent year databases have become an integral part of any Web based application. Their ability to easily store and retrieve data makes them idea for managing visitor data, cached data, application states, log information, etc. InterJinnTM comes with a default database service which removes connection information from the act of connecting to a database, and defines an abstraction layer for other databases to be used in place of the default MySQL server. THe benefits of such a layer may not be immediately apparent, but imagine you have an application which you would like to distribute. If you had the connection parameters sprinkled throughout the application then any attempt to use a different connection or even server would require the code to be updated at all these points. In contrast to this InterJinn allows the definition of multiple database connection parameters in the project configuration. This facilitates connecting to a database via a keyword rather than the low level parameters. the following example illustrates how easy it is to use the database service.
$qString =
"SELECT "
." login, "
."FROM "
." users ";
$dbManager = &$this->getService( 'dbManager' );
$db = &$this->unwrapObject( $dbManager->do->getConnection() );
$db->query( $qString );
while( $db->nextRow() )
{
echo $db->getField( 'login' );
}
$db->free();
Since there are obviously more database servers than MySQL, the modular structure of the InterJinn framework makes it easy to create an alternate database service which could provide connections to databases such as Oracle, PostgreSQL, or even mSQL. Taking this abstraction layer even further a connector service could be created to choose the correct database service which would simplify the mixing of heterogenous database servers into a single PHP application. An alternative database layer has already been created for you that wraps the PEAR DB set of classes. This provides access to many popular database servers. Check the Database Configuration Documentation to see how to enable the PEAR DB database service.
You can learn more about the database service by reading the Database Service Documentation. The same documentation will provide you with a list of methods and functionality that must exist in your own database service should you choose to create a custom one. You might also find the general Service Documentation useful.