Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

explaining use of $cfg->set_default_connection()

  • Loading branch information...
commit a21e9fb028dee0884161ed02a2b2619078d99ca9 1 parent 12fcc4d
Brian authored cvanschalkwijk committed
Showing with 25 additions and 4 deletions.
  1. +25 −4 README.md
29 README.md
View
@@ -48,26 +48,47 @@ Of course, there are some differences which will be obvious to the user if they
### Installation ##
-Setup is very easy and straight-forward. There are essentially only two configuration points you must concern yourself with:
+Setup is very easy and straight-forward. There are essentially only three configuration points you must concern yourself with:
1. Setting the model auto_load directory.
2. Configuring your database connections.
+3. Setting the database connection to use for your environment.
Example:
ActiveRecord\Config::initialize(function($cfg)
{
$cfg->set_model_directory('/path/to/your/model_directory');
- $cfg->set_connections(array('development' => 'mysql://username:password@localhost/database_name'));
+ $cfg->set_connections(
+ array(
+ 'development' => 'mysql://username:password@localhost/development_database_name',
+ 'test' => 'mysql://username:password@localhost/test_database_name',
+ 'production' => 'mysql://username:password@localhost/production_database_name'
+ )
+ );
});
Alternatively (w/o the 5.3 closure):
$cfg = ActiveRecord\Config::instance();
$cfg->set_model_directory('/path/to/your/model_directory');
- $cfg->set_connections(array('development' => 'mysql://username:password@localhost/database_name'));
+ $cfg->set_connections(
+ array(
+ 'development' => 'mysql://username:password@localhost/development_database_name',
+ 'test' => 'mysql://username:password@localhost/test_database_name',
+ 'production' => 'mysql://username:password@localhost/production_database_name'
+ )
+ );
+
+PHP ActiveRecord will default to use your development database. For testing or production, you simply set the default
+connection according to your current environment ('test' or 'production'):
+
+ ActiveRecord\Config::initialize(function($cfg)
+ {
+ $cfg->set_default_connection(your_environment);
+ });
-Once you have configured these two settings you are done. ActiveRecord takes care of the rest for you.
+Once you have configured these three settings you are done. ActiveRecord takes care of the rest for you.
It does not require that you map your table schema to yaml/xml files. It will query the database for this information and
cache it so that it does not make multiple calls to the database for a single schema.
Please sign in to comment.
Something went wrong with that request. Please try again.