Dear Team,
I connected multiple database with dynamically but model active record not working different database.Below my code
$originalDbConnection = Yii::app()->db;
$user_hostname="localhost";
$latin1DbConnection = Yii::createComponent(array(
'class'=>'CDbConnection',
'connectionString' =>'mysql:host=' . $user_hostname . ';dbname=' . $database,
'emulatePrepare' => Yii::app()->db->emulatePrepare,
'username' => $username,
'password' => $password,
'charset' => 'latin1',
));
Yii::app()->setComponent("db",$latin1DbConnection);
// Do the queries against the database
$model =Example::getLableName();
Yii::app()->setComponent("db",$originalDbConnection);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
Above the code multiple database with custom sql query working fine…but model active record not working.Please anyone can help me…