我正在使用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();
}
}
在此先感謝。