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.
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
-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
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
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
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
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:
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 =
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
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);
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.
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
12 matches
Mail list logo