title: Codeigniter : How to join 2 tables in databases from 2 different connections
body: <p>I made two database connections in <code>database.php</code>, one for reading which is my localhost machine and one for writing "insert" which is an online database.</p>
  
  <p>But I ran into this problem when I wanted to join the two tables "answers" in the localhost database and "user" in the online database.</p>
  
  <pre><code>    function get_users() {
      $write_db   = $this-&gt;load-&gt;database('default', TRUE); /* database conection for localhost DB */
      $read_db    = $this-&gt;load-&gt;database('read', TRUE); /* database conection for online DB */
  
      $read_db-&gt;select('*');
      $read_db-&gt;from('ibitstore.user');
      $write_db-&gt;join('english.answers','ibitstore.user.user_id = english.answers.user_id');
      $query = $read_db-&gt;get();
  
      if($query-&gt;num_rows() &gt; 0)
          return $query-&gt;result_array();
  
      return array();
  }
  </code></pre>
  
  <p>When I use <code>$write_db</code> with the join clause</p>
  
  <blockquote>
  <pre><code>  $write_db-&gt;join('english.answers','ibitstore.user.user_id = english.answers.user_id');
  </code></pre>
  </blockquote>
  
  <p>data is retrieved from the online database but not from the localhost database, like it ignored the join I tried to use:</p>
  
  <p><code>$read_db-&gt;join('english.answers','ibitstore.user.user_id = english.answers.user_id');</code></p>
  
  <p>Then I got this SQL error. Looks like it thought that the "answers" table is on the online DB:</p>
  
  <pre><code>A Database Error Occurred
  </code></pre>
  
  <p>Error Number: 1142</p>
  
  <p>SELECT command denied to user 'user'@'49.32.197.240' for table 'answers'</p>
  
  <pre><code>SELECT *
  FROM (`ibitstore`.`user`)
    JOIN `english`.`answers`
      ON `ibitstore`.`user`.`user_id` = `english`.`answers`.`user_id`
  </code></pre>
  
  <p>Filename: C:\xampp\htdocs\english\system\database\DB_driver.php</p>
  
  <p>Line Number: 330</p>
  
  <p>Please Help :(</p>