Skip to content

Commit a21e9fb

Browse files
Briancvanschalkwijk
Brian
authored andcommitted
explaining use of $cfg->set_default_connection()
1 parent 12fcc4d commit a21e9fb

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,47 @@ Of course, there are some differences which will be obvious to the user if they
4848

4949
### Installation ##
5050

51-
Setup is very easy and straight-forward. There are essentially only two configuration points you must concern yourself with:
51+
Setup is very easy and straight-forward. There are essentially only three configuration points you must concern yourself with:
5252

5353
1. Setting the model auto_load directory.
5454
2. Configuring your database connections.
55+
3. Setting the database connection to use for your environment.
5556

5657
Example:
5758

5859
ActiveRecord\Config::initialize(function($cfg)
5960
{
6061
$cfg->set_model_directory('/path/to/your/model_directory');
61-
$cfg->set_connections(array('development' => 'mysql://username:password@localhost/database_name'));
62+
$cfg->set_connections(
63+
array(
64+
'development' => 'mysql://username:password@localhost/development_database_name',
65+
'test' => 'mysql://username:password@localhost/test_database_name',
66+
'production' => 'mysql://username:password@localhost/production_database_name'
67+
)
68+
);
6269
});
6370

6471
Alternatively (w/o the 5.3 closure):
6572

6673
$cfg = ActiveRecord\Config::instance();
6774
$cfg->set_model_directory('/path/to/your/model_directory');
68-
$cfg->set_connections(array('development' => 'mysql://username:password@localhost/database_name'));
75+
$cfg->set_connections(
76+
array(
77+
'development' => 'mysql://username:password@localhost/development_database_name',
78+
'test' => 'mysql://username:password@localhost/test_database_name',
79+
'production' => 'mysql://username:password@localhost/production_database_name'
80+
)
81+
);
82+
83+
PHP ActiveRecord will default to use your development database. For testing or production, you simply set the default
84+
connection according to your current environment ('test' or 'production'):
85+
86+
ActiveRecord\Config::initialize(function($cfg)
87+
{
88+
$cfg->set_default_connection(your_environment);
89+
});
6990

70-
Once you have configured these two settings you are done. ActiveRecord takes care of the rest for you.
91+
Once you have configured these three settings you are done. ActiveRecord takes care of the rest for you.
7192
It does not require that you map your table schema to yaml/xml files. It will query the database for this information and
7293
cache it so that it does not make multiple calls to the database for a single schema.
7394

0 commit comments

Comments
 (0)