note 104609 modified in pdostatement.fetchall by danbrown
| From: | danbrown@php.net | Date: | Sun, 26 Jun 2011 16:00:23 +0000 |
| Subject: | note 104609 modified in pdostatement.fetchall by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180966@lists.php.net to get a copy of this message | ||
Note that fetchAll() can be extremely memory inefficient for large data sets. My memory limit was
set to 160 MB this is what happened when I tried:
<?php
$arr = $stmt->fetchAll();
// Fatal error: Allowed memory size of 16777216 bytes exhausted
?>
If you are going to loop through the output array of fetchAll(), instead use fetch() to minimize
memory usage as follows:
<?php
while ($arr = $stmt->fetch()) {
echo round(memory_get_usage() / (1024*1024),3) .' MB<br />';
// do_other_stuff();
}
// Last line for the same query shows only 28.973 MB usage
?>
--was--
Note that fetchAll() can be extremely memory inefficient for large data sets. My memory limit was
set to 160 MB this is what happened when I tried:
<?php
$arr = $stmt->fetchAll();
// Fatal error: Allowed memory size of 16777216 bytes exhausted
?>
If you are going to loop through the output array of fetchAll(), instead use fetch() to minimize
memory usage as follows:
<?php
while ($arr = $stmt->fetch()) {
echo round(memory_get_usage() / (1024*1024),3) .' MB<br />';
// do_other_stuff();
}
// Last line for the same query shows only 28.973 MB usage
http://php.net/manual/en/pdostatement.fetchall.php