看到这篇文章的时侯
两种统计数据库中记录数的方法
http://www.phpchina.com/bbs/thread-50496-1-1.html
以前不曾在意mysql_num_rows和select count()的效率问题,大错特错了
不曾注意是因为使用了一个别人写的mysql数据库操作类
其中提供了一个很方便的获取记录总数的方法 getnumber()
函数是这样滴
<?php
function getnumber($sql){
$this->result=$this->query($sql);
$number=mysql_num_rows($this->result);
$this->Free();
return $number;
}
?>
以前想都不曾想,用了就好,想一下就知道为什么select count()会快一些了