Eine zweite DbConnection
4. März 2011
'components' => array( 'db' => array( 'connectionString' => 'mysql:host=localhost;dbname=db1', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', ), 'db2' => array( 'class' => 'CDbConnection', //wichtig!! 'connectionString' => 'mysql:host=localhost;dbname=db2', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', ), ), $rows = Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll(); $rows2 = Yii::app()->db2->createCommand('SELECT * FROM tbl_user')->queryAll(); /* * soll ActiveRecord eine andere DbConnection benutzen, dann so */ public function getDbConnection() { return Yii::app()->getComponent('db2'); }
Verwandte Artikel:
Letzte Kommentare