Arun
Arun

Reputation: 59

Multiple Connections in Yii in a single query?

I need to copy a table in a database to another database both in same server in Yii. So for that i can use a single query to get all values but the query need to execute two databases. In Yii. I have db and db2 in my config file

so,

 $connection1 = Yii::app()->db1;

 $connection2 = Yii::app()->db2;

 $sql = "insert into test ()values()"; // Need two database table access ??

 $command = $connection->createCommand($sql);  //How can i execute using both connections??

 $row = $command->execute();

Please help..

Thanks!

Upvotes: 0

Views: 551

Answers (1)

Dmitriy Mozgovoy
Dmitriy Mozgovoy

Reputation: 46

If user in any DB connection have access to both tables you can transfer data just in one query. You need no second connection or query. You need just to use name of second database and use database.table names.

Upvotes: 2

Related Questions