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 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 if($num_rows > 0){
>     for($i=0; $i<$num_rows; $i++){
>        $c = mysql_result($result,$i,"contract");
> 
>        echo sprintf( "|%13d |%7d |\n", $c, $i );
>     }
> }
> 
> ?>
> 
> Best,
> Karl

Wow, working code!  Thanks.  I did try it:

<?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_seq";

$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 = mysql_result($result,$i,"contract");

      echo sprintf( "|%13d |%7d |\n", $c, $i );
   }
}

?>

But it does the same thing:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in /usr/local/www/apache22/data/bogus_copy/xx4.php on line 31

Line 31 is:

    31        $c = mysql_result($result,$i,"contract");


-- 
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