Yii 1.1 Use two database connection at same time

I want to use to database connection at the same time. I got two servers having same database. I want to update both the database at the same time i.e On the add/update/delete on my app both the database needs to up updated accordingly. I have added the following in the main.php


        'connectionString' => 'mysql:host=hostname;dbname=dbanme',

        'emulatePrepare' => true,

        'username' => 'username',

        'password' => 'password',

        'charset' => 'utf8',

        'tablePrefix' => 'tbl_',



        'class' => 'CDbConnection'

And then in my controller in the Add action :

public function actionCreate()


       $model=new TestTransaction;



            $originalDbConnection   = Yii::app()->db;

            $latin1DbConnection     = Yii::app()->db2;

            $model->attributes      = $_POST['TestTransaction'];

            if($model->save()) {











But this is not working. Please help me out.

In your TestTransaction model you can override getDBConnection method.

Here is good example http://www.yiiframework.com/wiki/123/multiple-database-support-in-yii/