findCount和count($rows)对比,哪个高?

#1 小双

 
$a = spClass("lib_order")->findCount();

 
$rows = spClass("lib_order")->findAll();
$a = ("" != $rows['id'])?count($rows):0;

上面两个谁的效率高些,一般推荐用哪个?

2011-07-23 10:24:00

#2 jake

当然是findCount效率高。

因为findCount是在mysql端count一次,返回一个结果数值
而上面的findAll,是把所有数据查询回来,再在PHP端count,这样即使是数量一样的情况下,通讯过程的开销就相差很远了——findCount只传输一个值,findAll是传送一堆记录。

2011-07-23 11:33:09