codeignitor活动记录嵌套查询问题 [英] Codeignitor active record nested select issue

查看:145
本文介绍了codeignitor活动记录嵌套查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeignitor我的PHP项目,但不是在它太多的经验。所以,请帮助我。

I am using codeignitor for my php project, but am not much experience in it. So, please help me.

我有两个数据库。 1. Kalix2 2.星号

I have two database. 1. Kalix2 2. Asterisk

在这两个数据库中我有一些表格。我想提出两个不同的数据库联接的表。我有以下的查询,它的正常工作在后台,但我不知道如何使用活动记录来实现它。

In both the database I am having some table. I want to make a join on the tables from two different database. I have the below query, it's working fine in back-end, but I don't know how to implement it using Active record.

SELECT  a.CompanyName, sum(ceil((b.billsec)/(c.Call_Limit*60))) as totalcall,
           hour(b.calldate) as use_hour FROM  Kalix2.ph_Companies a 
           INNER JOIN Asterisk.cdr b ON b.clid LIKE CONCAT('%', a.CompanyName, '%') 
           INNER JOIN Kalix2.ph_Plans c ON c.Comp_ID= a.Comp_ID 
           where  date(b.calldate)>='2013-01-15' and date(b.calldate)<='2013-1-20'  
           and c.Plan_Type='Per_Call' and a.CompanyName='ABCD' 
           group by hour(b.calldate);

请帮我把这个查询转换成积极的记录格式。先谢谢了。

Please help me to convert this query into active record format. Thanks in advance.

推荐答案

您应该可以,如果你想将其转换为活动的记录,但您将获得更好的性能,只需将这个来查询绑定。常见的错误是试图运行一个查询过多个类的:

You should be able to convert this to active record if you want but you will gain better performance by just converting this to Query Bindings. Common mistake is trying to run a query off of multiple classes:

$this->db1
$this->db2

这是行不通的,因为运行$这个 - > db1->获得(),因为它是只知道在DB1和DB2不是数据。冗长保持database.table信息的连接,只使用一个db对象,并使用分析器来调试查询生成,你应该是不错的。

This will not work because running $this->db1->get() because it is only aware of the data in db1 and not db2. Verbosely keep the database.table info in the joins, use only one db object, and use the profiler to debug the query generation and you should be good.

连接到多个数据库

活动记录类和加盟

调试使用探查查询

这篇关于codeignitor活动记录嵌套查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆