[PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread php
Running PHP 5.3.5 on FreeBSD 8.2 connecting to a MySQL 5.1.55 server. Why does this code (below) run out of memory? It queries test_table for all rows, all fields and sorts them by the numeric 'contract' field. It then iterates through the rows, and tallies the number of rows per contract.

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread tamouse mailing lists
On Thu, Oct 27, 2011 at 6:59 PM, p...@umpquanet.com wrote: Running PHP 5.3.5 on FreeBSD 8.2 connecting to a MySQL 5.1.55 server. Why does this code (below) run out of memory?  It queries test_table for all rows, all fields and sorts them by the numeric 'contract' field.  It then iterates

RE: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Toby Hart Dyke
-Original Message- From: p...@umpquanet.com [mailto:p...@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

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Karl DeSaulniers
That and maybe look into mysql_free_result() or mysql_freeresult() Best, Karl Sent from losPhone On Oct 27, 2011, at 9:08 PM, Toby Hart Dyke t...@hartdyke.com wrote: -Original Message- From: p...@umpquanet.com [mailto:p...@umpquanet.com] Sent: Thursday, October 27, 2011 8:00 PM

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread php
On Thu, Oct 27, 2011 at 09:17:21PM -0500, tamouse mailing lists wrote: That said, I think there must be a way to do this in SQL. Absolutely, there's a way to do this in SQL; select contract, sum(1) from test_table group by contract But as I said, simply counting is not the intent of the

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread tamouse mailing lists
On Thu, Oct 27, 2011 at 9:36 PM, p...@umpquanet.com wrote: On Thu, Oct 27, 2011 at 09:17:21PM -0500, tamouse mailing lists wrote: That said, I think there must be a way to do this in SQL. Absolutely, there's a way to do this in SQL; select contract, sum(1) from test_table group by contract

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread php
On Thu, Oct 27, 2011 at 09:50:14PM -0500, tamouse mailing lists wrote: Still, an inner and outer loop don't really seem necessary here, as you're spinning through one set of data, there doesn't seem a need to run through it that way. A more traditional method is to do something like:

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Karl DeSaulniers
Maybe this.. HTH, ?php ... $result = mysql_query( $qry, $db_conn ) or die( mysql_error() . \n ); $num_rows = mysql_numrows($result); if(!$result || ($num_rows = 0)){ echo Error displaying info; } else if($num_rows 0){ for($i=0; $i$num_rows; $i++){ $c =

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread php
On Thu, Oct 27, 2011 at 10:43:48PM -0500, Karl DeSaulniers wrote: Maybe this.. HTH, ?php ... $result = mysql_query( $qry, $db_conn ) or die( mysql_error() . \n ); $num_rows = mysql_numrows($result); if(!$result || ($num_rows = 0)){ echo Error displaying info; } else

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Karl DeSaulniers
Hmmm.. Try this.. for($i=0; $i$num_rows; $i++){ $c = mysql_result($result,$i,contract); echo sprintf( |%13d |%7d |\n, $c, $i ); mysql_free_result($c); //Free the memory with this. } or this.. for($i=0; $i$num_rows; $i++){ $c = mysql_result($result,$i,contract);

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Karl DeSaulniers
Here is a link for researching. http://php.net/manual/en/function.mysql-fetch-assoc.php HTH, Best, Karl On Oct 28, 2011, at 12:35 AM, Karl DeSaulniers wrote: Also, I don't know how your displaying this info, but if you have a good number of entries, you may want to look into pagination.

Re: [PHP-DB] Simple MySQL sample code runs out of memory

2011-10-27 Thread Karl DeSaulniers
Also, I don't know how your displaying this info, but if you have a good number of entries, you may want to look into pagination. Then your only grabbing a certain number of sets at a time not the whole database. Best, Karl On Oct 28, 2011, at 12:29 AM, Karl DeSaulniers wrote: Hmmm.. Try