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

I got a problem Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 141954624 bytes) when to count all of row mysql table

$query = $db->query("SELECT * FROM table");
$count = $db->num_rows($query);

echo $count;

Total rows about 17k and I got Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 141954624 bytes). Let me know, how to fix it.

You could change your SQL query to...

SELECT COUNT(*) AS `rows_count` FROM `table`;

Then you don't have to load such a large recordset to just then use a row counting function to get the number of rows.