For example:
Connections::add('default', array(
'type' => 'database',
'adapter' => 'MySql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'my_blog'
));
or
Connections::add('couch', array(
'type' => 'http', 'adapter' => 'CouchDb', 'host' => '127.0.0.1', 'port' => 5984
));
or
Connections::add('mongo', array('type' => 'MongoDb', 'database' => 'my_app'));
public static add ( string $name, array $config = [] ) : array | ||
$name | string | The name by which this connection is referenced. Use this name to retrieve the connection again using `Connections::get()`, or to bind a model to it using `Model::$_meta['connection']`. |
$config | array | Contains all additional configuration information used by the connection, including the name of the adapter class where applicable (i.e. `MySql`), the server name and port or socket to connect to, and (typically) the name of the database or other entity to use. Each adapter has its own specific configuration settings for handling things like connection persistence, data encoding, etc. See the individual adapter or data source class for more information on what configuration settings it supports. Basic / required options supported by most adapters: - `'type'` _string_: The type of data source that defines this connection; typically a class or namespace name. Relational database data sources, use `'database'`, while CouchDB and other HTTP-related data sources use `'http'`, etc. For classes which directly extend `lithium\data\Source`, and do not use an adapter, simply use the name of the class, i.e. `'MongoDb'`. - `'adapter'` _string_: For `type`s such as `'database'` which are adapter-driven, provides the name of the adapter associated with this configuration. - `'host'` _string_: The host name that the database should connect to. Typically defaults to `'localhost'`. - `'login'` _string_: If the connection requires authentication, specifies the login name to use. - `'password'` _string_: If the connection requires authentication, specifies the password to use. |
return | array | Returns the final post-processed connection information, as stored in the internal configuration array used by `Connections`. |