Be kind, tell me

How to change db (database) in Query Builder?

Example:

$q1 = (new \yii\db\Query()) ->select([ "col1", "col2", "col3" ]) ->from('table1'); $q2 = (new \yii\db\Query()) ->select([ "col1", "col2", "col3" ]) ->from('table2'); $query=$q1->union($q2); $query = \Yii::$app->db2->createCommand($query); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); 

The request is performed for a database that is db. I receive "Object of class yii \ db \ Query could not be converted to string"

Thank you for the answers.

  • You execute request for db2 ...... You looked that at you the request returns? - Alexey Shimansky

1 answer 1

 $dataProvider = new ActiveDataProvider([ 'query' => $query, 'db'=>\Yii::$app->db2, ]); 

 $arr=$query->all(\Yii::$app->db2); $dataProvider = new ArrayDataProvider([ 'allModels'=>$arr, ]); 

http://www.yiiframework.ru/forum/viewtopic.php?t=16210

  • Tell me, is this an answer or addition? - Nicolas Chabanovsky