Re: Simple MySQL sample code runs out of memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:
> 
> $last_contract = '';
> while ($row = $msql_fetch_assoc($results) {
>     if ($last_contract == $row['contract]) {
>         // do what ever you'd do with the same contract
>     } else {
>        $last_contract = $row['contract'];
>        // do what ever you'd do with the new contract
>     }
> }
> 
> assuming you are ordering by contract as in the example select.

Thanks for that suggestion, also.

Something more fundamental is going on.

Here is simpler code which still reproduces the problem.

<?php

require_once( '../include/mysql_funcs.php' );

$test_db_host = "localhost";
$test_db_user = "msm";
$test_db_pwd  = "EetGiOj6";
$test_db_name = "test_msm";

$db_host = $test_db_host;
$db_user = $test_db_user;
$db_name = $test_db_name;
$db_pwd  = $test_db_pwd;

if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd )))
	die( "Can't connect to MySQL server\n" );

if (!mysql_select_db( $db_name, $db_conn ))
	die( "Can't connect to database $db_name\n" );

$qry = "select * from test_spot_table order by contract";

if ($result = mysql_query( $qry, $db_conn )) {

	$n = 0;
	while ($row = mysql_fetch_array( $result )) {
		$n++;
	} // while
	echo "$n\n";

} else {

	die( mysql_error() . "\n" );

}

?>


I get:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 26

What's up with that?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux