统计指定条件的数量
integer Module_Database::count_records( [ mixed $table = null , $where = null ] )
参数列表
参数 类型 描述 默认值 $table
mixed
Table name string or array(query, alias) null $where
unknown
null
integer
public function count_records($table = null, $where = null)
{
if ($table)
{
$this->from($table);
}
if ($where)
{
$this->where($where);
}
// 记录当前builder信息
$builder = $this->_builder;
$this->select($this->expr_value('COUNT(1) AS `total_row_count`'));
$count = (int)$this->query($this->compile('select'), false)->get('total_row_count');
// 将之前获取的builder信息放倒_builder_bak上,以便可使用->recovery_last_builder()方法恢复前一个builder
$this->_builder_bak = $builder;
return $count;
}