Container for multiple DB Connections and allows switching.

Singleton Class stores the database connection information and creates db objects when they are first accessed via DBSelector::useDB() . This also allows them to be swapped as the active connection by scripts.
Also unsets connections if required. WARNING: see unsetDB().

package dstruct_common

 Methods

Store a DB Connection.

addConnectionString(string $connstring) : boolean
see \Prefs::DB_CONNECTIONS

Parameters

$connstring

string

Returns

boolean

Get a DB Connection.

getConnection(string $key) : boolean | \multitype:

If the connection has not already been made, it connects to the DB. Also sets the connection as the current connection.

Parameters

$key

string

Returns

boolean\multitype:

The current database connection in use.

getCurrent() : string

This does NOT have to be an active connection... the default (1st listed) connection is set as current when the variables are set.

Returns

string

Get an instance of the singleton object.

getInstance() : object
Static

Returns

objectDBSelector

Is the DB Connection connected yet?

isConnected(string $key) : boolean

If no $key is not specified, the method will return the state of the current connection.

Parameters

$key

string

Key ref for the connection

Returns

boolean

Retrieve a DB Connection OR array (doesn't try to connect).

retrieveDB(string $key) : mixed

Parameters

$key

string

Key ref for the connection

Returns

mixedConnection Object, array or False

Set the DB connection to use.

setCurrent(string $key) : boolean

Parameters

$key

string

Key ref for the connection

Returns

booleanReturns False if the key can not be found

Switch back to the previous DB used.

switchBackDB() 

Will only work if used in conjunction with DBSelector::switchToDB().

see \DBSelector::switchToDB()

Switch to a DB Connection.

switchToDB(\unknown $switchtokey) 

This can be used to switch to a connection while remembering the current. You can then call DBSelector::switchBackDB() to go back to the old connection.

see \DBSelector::switchBackDB()

Parameters

$switchtokey

\unknown

Unsets a database connection - UNTESTED.

unsetDB(string $key) : boolean

Parameters

$key

string

Key ref for the connection

Returns

booleanTrue on success, False on failure (connection doesn't exist in object)

Class constructor.

__construct() 

 Properties

 

$current : object
 

$instance : object
 

$props : array