Class As_DatabaseFactory

Description

THIS FILE IS NOT USED BY COUGH -- CoughDatabaseFactory is used instead. This is simply part of the original "as_database" module.

A simple factory that provides access to an application's database objects. It should be dynamically initialized, and can hold mixed types of database objects (e.g. PEAR::DB, AS Database, DatabaseConnector, Persistent).

EXAMPLE INITIALIZATION:

As_DatabaseFactory::addDatabase('content', new As_Database('content')); As_DatabaseFactory::addDatabase('user', new As_Database('user')); As_DatabaseFactory::addDatabase('new_user', new As_Database('new_user'));

EXAMPLE RETRIEVAL:

$db = As_DatabaseFactory::getDatabase('content');

Alternatively, you can have databases added on the fly as you request them by specifying the configuration for each database:

Assuming we have:

$dbConfigs = array( 'foo' => array( 'db_name' => 'new_user', 'host' => 'localhost', 'user' => 'nobody', 'pass' => '', 'port' => 3307, ), 'user' => array( 'db_name' => 'user', 'host' => 'localhost', 'user' => 'nobody', 'pass' => '', 'port' => 3306, ) );

Option 1: Add one config at a time:

As_DatabaseFactory::addDatabaseConfig('foo', $dbConfigs['foo']); As_DatabaseFactory::addDatabaseConfig('user', $dbConfigs['user']);

Option 2: Add all configs at once:

As_DatabaseFactory::setDatabaseConfigs($dbConfigs);

  • author: Anthony Bush

Located in /as_database/As_DatabaseFactory.class.php (line 56)


	
			
Variable Summary
static mixed $databases
static array $dbConfigs
Method Summary
static void addDatabase ( $dbName,  $dbObject)
static void addDatabaseConfig ( $dbObjName,  $dbConfig)
static void getDatabase ( $dbAliasName, [ $dbName = null])
static void setDatabaseConfigs ( $dbConfigs)
Variables
static mixed $databases = array() (line 57)
  • access: protected
static array $dbConfigs = array() (line 78)

An array of database config info.

When a database is retrieved, if it is not already created, then it gets created using the configuration info specified in this array, if that info exists.

Format:

[dbObjName] => array( 'db_name' => 'user', 'host' => 'localhost', 'user' => 'nobody', 'pass' => '', 'port' => 3306 );

  • access: protected
Methods
static method addDatabase (line 102)
  • access: public
static void addDatabase ( $dbName,  $dbObject)
  • $dbName
  • $dbObject
static method addDatabaseConfig (line 98)

Sets the database config for the specified database object name.

static void addDatabaseConfig ( $dbObjName,  $dbConfig)
  • $dbObjName
  • $dbConfig
static method getDatabase (line 106)
  • access: public
static void getDatabase ( $dbAliasName, [ $dbName = null])
  • $dbAliasName
  • $dbName
static method setDatabaseConfigs (line 87)

Sets all the database configs at once.

static void setDatabaseConfigs ( $dbConfigs)
  • $dbConfigs

Documentation generated on Wed, 12 Nov 2008 21:56:10 -0600 by phpDocumentor 1.4.0