Zeta Components Manual :: Docs For Class ezcDbInstance
Database::ezcDbInstance
Class ezcDbInstance
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// |
Method Summary
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. |
Methods
chooseDefault
Sets the database $identifier as default database instance.
To retrieve the default database instance call get() with no parameters..
Parameters:
Name | Type | Description |
---|---|---|
$identifier |
string |
get
Returns the database instance $identifier.
If $identifier is ommited the default database instance specified by chooseDefault() is returned.
Parameters:
Name | Type | Description |
---|---|---|
$identifier |
string |
Exceptions:
Type | Description |
---|---|
ezcDbHandlerNotFoundException |
if the specified instance is not found. |
getIdentifiers
Returns the identifiers of the registered database instances.
reset
Resets this object to its initial state.
The list of instances will be emptied and resetDefault() will be called.
resetDefault
Resets the default instance holder.
set
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.
Parameters:
Name | Type | Description |
---|---|---|
$db |
ezcDbHandler | |
$identifier |
string | the identifier of the database handler |