I wondered if someone could offer me some advice.
Each of my clients connects to a different database. Sometimes I need to perform tasks using scripts that run on the CRON and connect to each database one at a time in a loop. Because many of the methods called are also used within the application through the front end I cannot always use name spacing for the queries e.g. SELECT * FROM database.tablename. I therefore need to change the Yii::app()->db component dynamically for example:
foreach($databases as $database){
//Override just the db connectionString (DOES NOT WORK)
Yii::app()->db->connectionString="mysql:host=localhost;dbname=$database";
$sql="SELECT * FROM sometable";
$command=Yii::app()->db->createCommand($sql);
$column = $command->queryColumn();
}
The above clearly does not work but it is the kind of functionality I am trying to achieve. I can't really use:
$connection=new CDbConnection($dsn,$username,$password); $connection->active=true;
Because when the routines are run via the web front end it needs to read the db component from the main.php config file.
I am currently a bit lost as to how to achieve this properly. Should my script be some sort of console application that would allow me to do this more easily? Is there a way to change the db connectionString and connect to different DBs in a loop?
Any advice would be appreciated.

Help













