CodeIgniter活动记录与常规查询 [英] CodeIgniter Active Record vs. regular queries

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

问题描述

目前我使用CodeIgniter与常规查询,即:

  $ sql =
SELECT *
FROM my_table
WHERE item_id> 1
;
$ q = $ this-> db-> query($ sql);

我开始研究ActiveRecord,它看起来不错,内建不管使用哪个数据库驱动程序 - 但是,我严格使用单个数据库类型每个项目一般,所以这不是真的对我有好处。



我发现在我看来,常规查询(我在我的例子中)更易读和更容易维护,所以我目前正在考虑保持常规查询。 / p>

除了上述原因,我应该选择什么原因,还有什么原因?



解决方案

对我来说,我更喜欢运行常规查询,CI的活动记录消耗了很多内存。因为它会将所有结果加载到内存中。如果你明白我的意思。至于复杂性,最好使用常规查询,而不是使用CI的活动记录sytax。


Currently I use CodeIgniter with regular queries, i.e.:

$sql = "
    SELECT *
    FROM my_table
    WHERE item_id > 1
";    
$q = $this->db->query($sql);

I have started looking into ActiveRecord, and it does look nice, and has the advantage of the query being built regardless of which database driver is used - however, I strictly use a single database type per project in general, so this is not really a benefit for me.

I found that regular queries (as I have in my example) are more readable and easier maintained in my opinion, so I am currently thinking of keeping with regular queries.

Besides for the reasons mentioned above, which should I choose, and for what reason(s)?

Thank you

解决方案

well for me i prefer running regular queries, CI's active record consumes to much memory. because it will load all result in the memory. If you know what i mean. As for complexity it's better to go with regular query rather sticking to CI's active record sytax.

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

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