## Apache 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:

1. $db=ezcDbFactory :: create ($dbparams);
2. ezcDbInstance :: set ($db);
4. // ...
6. $db=ezcDbInstance :: get ();

More complex example, with two connections, having identifiers (for convenience):

1. $mydb=ezcDbFactory :: create ($mysql_dbparams);
2. $pgdb=ezcDbFactory :: create ($pgsql_dbparams);
4. ezcDbInstance :: set ($mydb,'my');
5. ezcDbInstance :: set ($pgdb,'pg');
6. ezcDbInstance :: chooseDefault ('my');
8. // ...
10. $mydb=ezcDbInstance :: get ('my');// returns the mysql instance
11. $pgdb=ezcDbInstance :: get ('pg');// returns the pgsql instance
12. $mydb=ezcDbInstance :: get ();// returns the mysql instance which is default

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

static void chooseDefault( string $identifier )

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

static ezcDbHandler get( [string $identifier = false] )

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

static array(string) getIdentifiers( )

Returns the identifiers of the registered database instances.

#### reset

static void reset( )

Resets this object to its initial state.

The list of instances will be emptied and resetDefault() will be called.

#### resetDefault

static void resetDefault( )

Resets the default instance holder.

#### set

static void set( ezcDbHandler $db , [string $identifier = false] )

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

Documentation generated by phpDocumentor 1.4.3