简体   繁体   English

如何计算 mysql 中的总行数而不会出现致命错误:允许 memory

[英]How do I count total of row in mysql without get Fatal error : Allowed memory

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我遇到了一个问题Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 141954624 bytes)何时计算所有行 mysql 表

$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) .总行数约为 17k,我得到了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...您可以将 SQL 查询更改为...

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.然后,您不必加载如此大的记录集,然后使用行计数 function 来获取行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM