title: Yii 2 - How to set connection in DB Query for multi database
body: <p>How to set db connection in yii-db-query?</p>
  
  <p>I have a <strong>3 database connection</strong>:</p>
  
  <blockquote>
    <p>db, db2 and db3</p>
  </blockquote>
  
  <p>When I used this default <strong>Query</strong>:</p>
  
  <pre><code>$query = (new \yii\db\Query())
              -&gt;select('*')
              -&gt;from('trans_journal')
              -&gt;all();
  </code></pre>
  
  <p>It will <strong>return an</strong> <strong>error</strong>. The <strong>trans_journal</strong> is not <strong>found</strong>, because the <strong>trans_journal</strong> is from the <strong>db2 connection</strong>.</p>
  
  <p>And when I used this <strong>Query</strong>:</p>
  
  <pre><code>$query = (new \yii\db\Query())
              -&gt;select('*')
              -&gt;from('trans_journal')
              -&gt;all(\Yii::$app-&gt;db2);
  </code></pre>
  
  <p>The query will be successfully generated but the problem is it will <strong>return an array</strong>.</p>
  
  <p>Is there another way to solved this?</p>