note 104609 added to pdostatement.fetchall
| From: | Anonymous at osu1 dot php dot net | Date: | Sat, 25 Jun 2011 21:10:18 +0000 |
| Subject: | note 104609 added to pdostatement.fetchall | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180950@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
----
Server IP: 69.147.83.197
Probable Submitter: 190.241.39.11
----
Manual Page -- http://www.php.net/manual/en/pdostatement.fetchall.php
Edit -- https://master.php.net/note/edit/104609
Del: integrated -- https://master.php.net/note/delete/104609/integrated
Del: useless -- https://master.php.net/note/delete/104609/useless
Del: bad code -- https://master.php.net/note/delete/104609/bad+code
Del: spam -- https://master.php.net/note/delete/104609/spam
Del: non-english -- https://master.php.net/note/delete/104609/non-english
Del: in docs -- https://master.php.net/note/delete/104609/in+docs
Del: other reasons-- https://master.php.net/note/delete/104609
Reject -- https://master.php.net/note/reject/104609
Search -- https://master.php.net/manage/user-notes.php