Main façade of direct database connection system. The main purpose of the class is to hold a list of specific connections to the database, and possibly create new connections ad hoc.

Method Overview

Method Meaning of
public static get(
?string $connection_name = null
Returns an instance of the specified database connection that can already be used to perform the necessary operations.
  • $connection_name
    The name of the database connection (configuration) that you want to use to work with the database. If the parameter is not specified, then the default connection is used.
public static getConfig(
): Db_Config
Returns the definition of the main Db configuration. That is, not the configuration of one particular connection, but the entire definition including all defined connections, specifying the default connection (and any other parameters, if defined).
public static setConfig(
Db_Config $config
): void
Sets the entire Db configuration definition. So for example all defined connections, selection of default connection and so on.
public static createConnection(
string $connection_name,
array $connection_config_data
): Db_Backend_Interface
Ad hoc creates the database connection definition not according to the application configuration, but according to the parameters defined in a conventional way - by the associated field.
The connection to the database is initialized and the connection instance is returned - thus the required operations can be performed directly.

This method is useful, for example, for a single-purpose script where you need to temporarily connect to a third-party database, for example, and for various reasons it may not be entirely appropriate to put the connection definition into the application configuration.
Previous chapter
Next chapter