multiple DB connection types

Lets say I have a local, test, and live database for my app. 

is there a way to specify which db connection to use?


i thing that you should modify connectionString, username and password from CDbConnection in your controller class.

Yes I am aware that is how you specificy db settings.

What I'm referring to is, can there be support for

'db'=>array('local' => array(

		'class' => 'CDbConnection',


		'username' => 'root',

		'password' => ''



                'test' => array(…),

                'live' => array(…),


You may refer to this article written by Jonah:


I would like to extend to question

I would like read from one database and when I write I would like to use another database for security issue. Is there an way I can define 2. or 3 database connection settings in one config file or I have to use other config file ?

You can configure an additional DB application component, for example, 'db2'. Then you can use Yii::app()->db2 to access this new DB connection.