简体   繁体   English

活动记录表现; $ this-> db链接或重复

[英]active record performance; $this->db chained or repetitive

I'm writing a lot of queries in codeigniter. 我在codeigniter中写了很多查询。 I use Active Record and I can do: 我使用Active Record,可以做到:

$this->db->select('*');
$this->db->from('example');
$query = $this->db->get();
return $query->result_array();

or 要么

return $this-db->select('*')
->from('example')
->get()
->result_array()

I find the bottom one more readable, but I was wondering if the eventual SQL query and/or the performance are affected by the way of writing the AR queries. 我发现最底层的代码更具可读性,但是我想知道最终的SQL查询和/或性能是否受到编写AR查询的方式的影响。

The speed should be about the same with both as PHP will just compile the SQL for you when you use Active Record. 两者的速度应该差不多,因为当您使用Active Record时,PHP只会为您编译SQL。

The easiest way to check this would be to include $this->output->enable_profiler(TRUE); 最简单的检查方法是包括$this->output->enable_profiler(TRUE); in the constructor (or method) of your controller which will show you exactly how long the different queries (and more) took. 在控制器的构造函数(或方法)中,它将确切显示不同查询(以及更多查询)花费了多长时间。

Hope this help! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM