RE: [PHP-DB] Simple MySQL sample code runs out of memory
| From: | Toby Hart Dyke | Date: | Fri, 28 Oct 2011 02:08:29 +0000 |
| Subject: | RE: [PHP-DB] Simple MySQL sample code runs out of memory | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48064@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: php@umpquanet.com [mailto:php@umpquanet.com]
Sent: Thursday, October 27, 2011 8:00 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Simple MySQL sample code runs out of memory
Running PHP 5.3.5 on FreeBSD 8.2 connecting to a MySQL 5.1.55 server.
<snip>
$row = mysql_fetch_array( $result );
while ($row) {
...
</snip>
Your while() condition will always be true, so that loop will run forever.
Until you run out of memory.
What you probably meant was to replace those two lines with something like
this:
while($row = mysql_fetch_array( $result ) ) {
A new row is fetched each time the while loop goes through another
iteration, until you run out of rows and the condition evaluates to false.
Toby