i read the yii docs and the following code should work;
well, it doesnt. :))
db is the primary database
db1 and db2 are the secondary databases
what is wrong here ?
the website is online, at www.linkbook.co, and it cant connect to any of the databases
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=linkbookco',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => '',
),
'db1' => array(
'connectionString' => 'mysql:host=localhost;dbname=linkbookco1',
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => '',
'class' => 'CDbConnection' // DO NOT FORGET THIS!
),
'db2' => array(
'connectionString' => 'mysql:host=localhost;dbname=linkbookco2',
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => '',
'class' => 'CDbConnection' // DO NOT FORGET THIS!
),
dbis the predefined component ofYii, so bedefaultCActiveRecordmakes connection usingdb. So for other components you have created usingCDbConnectionclass you have to activate connection for them externally.SO You need to overwrite
getDbConnection()method ofCActiveRecord.Extend the
CActiveRecordfor specific database connection likedb1.Save this as
Db1CActiveRecord.phpand place in components directory.Now you need to use
Db1CActiveRecordfor the model class of databasedb1.Like:
Implement this way for both db1 & db2 database.