title: Codeigniter Active Record select on multiple databases
body: <p>I need some help to figure out how to make a select from tables in multiple databases using Active Record in Codeigniter.</p>
  
  <p>In details: I have two database; in the first one there is a table named users with all details about user (first name, last name and so on); in the second database there is a table named credit where there are credit info about each user; the user_id is the key that links the tables.</p>
  
  <p>In the contruct Model I have:</p>
  
  <pre><code>public function __construct()
      {
          parent::__construct();
          $this-&gt;rci_db = $this-&gt;load-&gt;database('dev', TRUE);
      }
  </code></pre>
  
  <p>The query to select the data is:</p>
  
  <pre><code>$this-&gt;db-&gt;select (" 
              $this-&gt;t_users.user_id,
              $this-&gt;t_users.username,
              $this-&gt;t_users.first_name,
              $this-&gt;t_users.last_name,
              $this-&gt;t_users.email,
              $this-&gt;t_users.lastlogin,
              $this-&gt;t_contributers.user_id AS credit
              ");
          $this-&gt;db-&gt;from($this-&gt;t_users);
          $this-&gt;db-&gt;join($this-&gt;rci_db.$this-&gt;t_contributers, "$this-&gt;t_contributers.user_id = $this-&gt;t_users.user_id");
  </code></pre>
  
  <p>The query doesn't work and I get the following error:</p>
  
  <pre><code>Error Number: 1146
  
  Table 'gavsit_data.rci_imgcontributers' doesn't exist
  
  SELECT `users`.`user_id`, `users`.`username`, `users`.`first_name`, `users`.`last_name`, `users`.`email`, `users`.`lastlogin`, `rci_imgcontributers`.`user_id` AS `credit` FROM `users` JOIN `rci_imgcontributers` ON `rci_imgcontributers`.`user_id` = `users`.`user_id` ORDER BY `id` ASC
  
  Filename: models/adm/Users_model.php
  </code></pre>
  
  <p>Thanks a lot for any hint...I really don't know how to figure out this issue.</p>
  
  <p>EDIT:
  I've edited the code splitting the select query, the error has gone but I got no data from the second DB:</p>
  
  <pre><code>   $this-&gt;db-&gt;select (" 
              $this-&gt;t_users.id,
              $this-&gt;t_users.username,
              $this-&gt;t_users.first_name,
              $this-&gt;t_users.last_name,
              $this-&gt;t_users.email,
              $this-&gt;t_users.last_login,
              $this-&gt;t_users.active
              ");
          $this-&gt;rci_db-&gt;select("
              $this-&gt;t_contributers.user_id,
              $this-&gt;t_contributers.cbtid
              ");
          $this-&gt;db-&gt;from($this-&gt;t_users);
          $this-&gt;rci_db-&gt;join("$this-&gt;t_contributers", "$this-&gt;t_contributers.user_id = $this-&gt;db.$this-&gt;t_users.id", 'left');
  </code></pre>