Hi,
the wiki is out of date. Yii feature have envolved since Jul 30, 2010 !
Now the framework has a nice multidb support, with transparent AR calls through different dbs.
you always have to declare your dbs in config/main.php:
'components'=>array(
.........
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=database1',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'itsasecret',
'charset' => 'utf8',
),
'db2'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=database2',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'itsasecret',
'charset' => 'utf8',
),
....
),
the in you model/MyModel.php you have to declare the db connection:
/**
* @return CDbConnection database connection
*/
public function getDbConnection()
{
return Yii::app()->db; // or return Yii::app()->db2;
}
Notes:
1/ gii (giix also and maybe other generators found in extensions directory), already handle this feature: you can select the db to use for the model generation: Excellent!
2/ db system can be from differnet types (mysql, postgres and so on) and also be hosted on different servers: Brillant !
3/ all relations works transparently: Amazing !
So you can use:
$users = User::model()->with('profile')->findAll();
where User model is from db, and Profile model from db2 and User model has_one Profile declared in its relations array as ‘profile’
how simple. Thank you Yii