Holds database instances for global access throughout an application.
It is common for many application to use only one or very few database connections. This class holds a single database connection name or a list of databases identified by a handle. The database connections can be retrieved from anywhere within your code through the static methods. This eliminates the need to pass the connection handle around.
Typical usage example:
More complex example, with two connections, having identifiers (for convenience):
Source for this file: /Database/src/instance.php
Version: | //autogentag// |
public static void |
chooseDefault(
$identifier
)
Sets the database $identifier as default database instance. |
public static ezcDbHandler |
get(
[ $identifier
= false] )
Returns the database instance $identifier. |
public static array(string) |
getIdentifiers(
)
Returns the identifiers of the registered database instances. |
public static void |
reset(
)
Resets this object to its initial state. |
public static void |
resetDefault(
)
Resets the default instance holder. |
public static void |
set(
$db
, [ $identifier
= false] )
Adds the database handler $db to the list of known instances. |
Sets the database $identifier as default database instance.
To retrieve the default database instance call get() with no parameters..
Name | Type | Description |
---|---|---|
$identifier |
string |
Returns the database instance $identifier.
If $identifier is ommited the default database instance specified by chooseDefault() is returned.
Name | Type | Description |
---|---|---|
$identifier |
string |
Type | Description |
---|---|
ezcDbHandlerNotFoundException |
if the specified instance is not found. |
Returns the identifiers of the registered database instances.
Resets this object to its initial state.
The list of instances will be emptied and resetDefault() will be called.
Resets the default instance holder.
Adds the database handler $db to the list of known instances.
If $identifier is specified the database instance can be retrieved later using the same identifier.
Name | Type | Description |
---|---|---|
$db |
ezcDbHandler | |
$identifier |
string | the identifier of the database handler |