Cool Penguin

PersistClass for PHP - keeping SQL simple

Tutorial

Open database connection

You can access the database through a DbConnection object. At the moment PersistClass contains DbConnection implementations for MySQL and Oracle. The following example shows how to create connection object.

$myConnection = new DbConnectionMysql();
$myConnection->connect('localhost', 'demouser', 'demopassword', 'demodatabase'); 

You can register a connection object into the DbConnectionPool

DbConnectionPool::instance()->registerConnection($myConnection);

You can get your connection object any time using the connection pool.

$con = DbConnectionPool::instance()->getConnection();

You can even register multiple database connections by providing a connection name:

DbConnectionPool::instance()->registerConnection($myOtherConnection, 'myotherconnection');
$otherCon = DbConnectionPool::instance()->getConnection('myotherconnection');