lithium\data\Connections::add()
Add connection configurations to your app in config/bootstrap/connections.php
For example:
Connections::add('default', [
'type' => 'database',
'adapter' => 'MySql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'my_blog'
]);
or
Connections::add('couch', [
'type' => 'http',
'adapter' => 'CouchDb',
'host' => '127.0.0.1',
'port' => 5984
]);
or
Connections::add('mongo', [
'type' => 'MongoDb',
'database' => 'my_app'
]);
Parameters
-
string
$name
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 usingModel::$_meta['connection']
. -
array
$config
Contains all additional configuration information used by the connection, including the name of the adapter class where applicable (i.e.
MySql
), and typcially the server host/socket to connect to, 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 are:'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 extendlithium\data\Source
, and do not use an adapter, simply use the name of the class, i.e.'MongoDb'
.'adapter'
string: Fortype
s such as'database'
which are adapter-driven, provides the name of the adapter associated with this configuration.
Returns
arrayReturns the final post-processed connection information, as stored in the
internal configuration array used by Connections
.
Source
public static function add($name, array $config = []) {
$defaults = [
'type' => null,
'adapter' => null
];
return static::$_configurations[$name] = $config + $defaults;
}