Select Columns Across Different Databases


how can i select columns across different databases in Yii framework with use createCommand() function?

Important to me is : don’t write direct call to database( i want use Yii::app()->db instead rl name of database).

It’s a possible? how can i do that?

I have seen google info about using multiple db connection with Yii, maybe it could help.

Yes you can. Just create new CDbCommand with new CDbConnection:

$cn = new CDbConnection();

// set connection string to connect to the any database you want

// replace host_name and database_name with real values

$cn->connectionString = 'mysql:host=host_name;dbname=database_name';


$command = new CDbCommand($cn);

// replace col_name, table_name and some_value with real values

$command->select('col_name1, col_name2')


        ->where('col_name3 = some_value')