Marcolini
(Marco Alves00)
March 16, 2012, 6:38pm
1
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
Marcolini
(Marco Alves00)
March 16, 2012, 6:41pm
2
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
MiDo0o0o
(Mr Aibrahim)
March 22, 2012, 9:57am
3
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
redguy
(Maciej Lizewski)
March 22, 2012, 10:53am
4
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...
...
}
ranairfan
(Rana Irfan202)
October 31, 2012, 7:20am
6
Marcolini:
solved
how you done this ? i also want to do this
Marcolini
(Marco Alves00)
November 27, 2012, 4:51pm
7
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]