Contains management system for database connections. dbManager can handle multiple separate connection instances simply by using alternative connection credentials.
dbManager is a static class and should always be called via dbManager::getInstance(). It can be called without any parameters but only if either: a default DSN has already been set OR if there is a system configured DSN in systemConfig::getDatabaseDsn().
dbManager can be instanatied with either a fully qualified DSN string in a supported form (see dbOptions::parseDsn()) or a pre-built dbOptions object.
// most simple usage, using system defaults
$oDb = dbManager::getInstance();
// with custom DSN
$oDb = dbManager::getInstance('sqlite3:///somedb.db');
// using dbOptions
$oDb = dbManager::getInstance(new dbOptions());
dbManager will cache the first requested instance as the default DSN for all further requests. To change this you can at any time use dbManager::setDefaultDsn(). This takes a dbOptions object.
// example setting default dsn $dbOptions = new dbOptions(); // set options ... // now register as default dbManager::setDefaultDsn($dbOptions); // uses new default dsn $oDb = dbManager::getInstance();
private __construct()
Prevent dbManager being instantiated
public static getInstance([$inDsn = false])
Connects to a database instance with the supplied DSN string or dbOptions object. DB objects are cached using the properties of the dbOptions object, if no DSN is specified and the defaultDsn has been set, this connection is immediately returned.
public static setDefaultDsn($oDbOptions)
Set the dbOptions to be the default connection
public static getDefaultDsn()
Returns the current default DSN options object, or false if not set
public static clearInstances()
Removes all active instance from the container, returns number removed