Ar Scenario To Connect Database


Simple question - can i use "scenario" to connect to database? For example :

$model1 = new ARecord('database1'); //get data from first database

$model2 = new ARecord('database2'); //get data from second database

foreach($model1 as $row)


    echo $row->name;


foreach($model2 as $row)


    echo $row->name;


Can i do that with active record scenario? If i can’t, how i simple change database in active record?

Thanks for reply

I using following solution :

public static $server_id = 2;

    public static $master_db;

    public function getDbConnection() {

        self::$master_db = Yii::app()->{"db" . self::$server_id};

        if (self::$master_db instanceof CDbConnection) {


            return self::$master_db;



            throw new CDbException(Yii::t('yii', 'Active Record requires a "db" CDbConnection application component.'));