How to manage multiple Databases and Schemas using YII framework

Hi all,

I read the articles about managing multiple Databases with yii framework, but they all lack of scalability (bad programing) or they can only access a specific database that we pretend (one at a time).

What i want is to get all the information from at least 2 Databases (select *) in different schemas, at simultaneous. Like a merge of the results of the DB’s.

If someone could help me i would apreciate.

Thank you

i managed to do it but it lacks in scalability. If i want to add a new DB i have to change a lot of files .php

I want to use yii in developing of my company’s erp system but lacking of this feature preventing me, I hope that it will be exist in 2.0

maybe you should try this solution: http://www.yiiframework.com/forum/index.php/topic/29746-connecting-to-different-databases-in-a-script/page__view__findpost__p__143183

in short:




 array(

    ......

    'components'=>array(

        ......

        'db1'=>array(

            'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=testdb1',

            'username'=>'root',

            'password'=>'password',

            'emulatePrepare'=>true,  // needed by some MySQL installations

        ),

        'db2'=>array(

            'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=testdb2',

             ...

        ),

      ...

    ),

  ...

)



and then iterate through all application components:




 foreach(Yii::app()->getComponents() as $component)

  if ($component instanceof CDbConnection) 

  {

    ...

     $component->createCommand($sql)->query();

     //merge results...

    ...

  }



solved :)

how you done this ? i also want to do this

Ranairfan,

I did do it but its not working with two DBs simultaneous. I configured 2 DBs (like redguy did above) and query them one each time.

True its not efficient like i was looking for but it works :)

in short its like:

What i wanted:

SELECT * FROM users,projects

What i did to work:

[b]SELECT * FROM users

SELECT * FROM projects[/b]