且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在codeigniter中加入两个数据库的查询

更新时间:2023-09-16 21:56:04

如果你需要连接两个数据库表,你可以只给出以下内容:

You can just give the following if you need to join two database tables:

function get_per_company_total_use ($custid)
        {         
                 $this->db->select('Kalix2.ph_Companies.CompanyName');
                 $this->db->where('Kalix2.ph_Companies.Cust_ID', $custid);
                 $this->db->select_sum('Asterisk.cdr.call_length_billable')->from('Asterisk.cdr');
                 $this->db->group_by('Asterisk.cdr.CompanyName');
                 $this->db->join('Kalix2.ph_Companies', 'Kalix2.ph_Companies.CompanyName = Asterisk.cdr.CompanyName');
                 $query = $this->db->get();
                 if($query->result()){
                     foreach ($query->result() as $value) {
                         $companies[]= array($value->CompanyName,$value->call_length_billable);
                          }
                     return $companies;
                 }
                 else 
                     return FALSE;
        }

这里其实不需要给连接变量DB1或DB2,只要给$this->db即可.

Here actually you need not give the connection variable DB1 or DB2, just give $this->db.