要获取记录总数,我通常使用以下查询:
$total= mysql_num_rows(mysql_query("SELECT id FROM t_statistic WHERE pageid = $pid"));
但我得到了另一个查询,如下所示:
$data = mysql_fetch_object(mysql_query("SELECT COUNT(id) AS num_rows FROM t_statistic WHERE pageid = $pid"));
$total = $data->num_rows;
在上面的两个查询之间。哪个更快更有效(当记录总数以百万计时)?