简体   繁体   中英

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

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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