title: Join query of two databases in codeigniter
body: <p>I need to write a join query of two tables from two databases and fetch the joined data.
  For eg, consider I have a database db1 which has some tables named companies, plans, customers. Suppose I need to join the two tables companies and plans with another table 'cdr' on another database db2 by grouping them using a similar column.</p>
  
  <p>The query which I'm running right now is given below:</p>
  
  <pre><code>function get_per_company_total_use ($custid)
          {         
                   $this-&gt;DB1-&gt;select('ph_Companies.CompanyName');
                   $this-&gt;DB1-&gt;where('ph_Companies.Cust_ID', $custid);
                   $this-&gt;DB2-&gt;select_sum('cdr.call_length_billable')-&gt;from('cdr');
                   $this-&gt;DB2-&gt;group_by('cdr.CompanyName');
                   $this-&gt;db-&gt;join('Kalix2.ph_Companies', 'Kalix2.ph_Companies.CompanyName = Asterisk.cdr.CompanyName');
                   $query = $this-&gt;db-&gt;get();
                   if($query-&gt;result()){
                       foreach ($query-&gt;result() as $value) {
                           $companies[]= array($value-&gt;CompanyName,$value-&gt;call_length_billable);
                            }
                       return $companies;
                   }
                   else 
                       return FALSE;
          }
  </code></pre>
  
  <p>But my query is not fetching the data and throwing an error. This same query, I have run on a single database and is working. But I need help to find how this can be done with two databases.</p>