I am using codeigniter framework. I am not much experienced in this framework. I need help of you guys. I want to join two table present in two different database. In both the table I have one common column. I understand, first I have to create a separate database group inside the file database.php. I have created the group and am able to use ths group in my model separately. I have also loaded another group in my model "default group". Whenever, I am trying to use each group separately it's working without any issue. But I am struggling how to make join on two database using these two database group.
Now I want to join two tables of different database using these two separate group. But I am not sure where exactly I am doing the mistake.
This is my model file.
class Bar_graph extends CI_Model {
public function __construct () {
parent::__construct();
$this->db= $this->load->database('default', TRUE);//This is the default group
$this->db2 = $this->load->database('db2', TRUE); //This is the new group I have created
}
//kalix2 and Asterik are my two different database
public function join_two_database ()
{
$cust_id=2;
$this->db->select('Kalix2.ph_Companies.CompanyName');
$this->db2->select_sum('Asterik.cdr.call_length_billable');
$this->db2->select('Asterik.cdr.calldate');
$this->db->where('Kalix2.ph_Companies.Cust_ID',$cust_id);
$this->db->from('Kalix2.ph_Companies');
$this->db2->group_by('Asterik.cdr.CompanyName');
$this->db->limit(5);
$this->db->join('Asterik.cdr','Kalix2.ph_Companies.CompanyName = Asterik.cdr.CompanyName','inner');
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query-> result();
}
}