我正在使用codeignitor框架。我在这个框架方面经验不足。我需要你们的帮助。我想要在两个不同的数据库中加入两个表。在这两张表中我都有一个共同的专栏。我明白,首先我必须在文件database.php中创建一个单独的数据库组。 我已经创建了该组,并且能够分别在我的模型中使用该组。我还在我的模型“默认组”中加载了另一个组。每当我尝试分别使用每个组时,它都没有任何问题。但我正在努力如何使用这两个数据库组加入两个数据库。Codeignitor多数据库连接
现在我想要使用这两个单独的组加入两个不同数据库的表。但我不确定我到底在做什么错误。
这是我的模型文件。
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();
}
}
在此先感谢。