我如何在没有得到致命错误的情况下计算mysql中的行总数:允许的内存

问题描述

|| 计数所有行MysqL表时出现问题
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 141954624 bytes)
$query = $db->query(\"SELECT * FROM table\");
$count = $db->num_rows($query);

echo $count;
总行数约17k,我得到
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 141954624 bytes)
。让我知道如何解决。     

解决方法

        您可以将SQL查询更改为...
SELECT COUNT(*) AS `rows_count` FROM `table`;
然后,您不必加载这么大的记录集即可使用行计数功能来获取行数。