Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I can't undertsand why this is occuring

    PHP Code:
    <?php
    include('includes/config.php');
    $isbn=array(); $ean11=array();$inc2=0;
    $db_name2='mpmp';
        
    mysql_select_db($db_name2);

    $sql="SELECT EAN11 from ttt"
    $result=mysql_query($sql);
        
        
    $inc2=0;
        while(
    $row=mysql_fetch_array($result))
        {    

          
    $ean11[$inc2]=$row['EAN11'];
          
    $inc2++;
        }

    $db_name2='aa';
     
    mysql_select_db($db_name2);
                
    $sql="SELECT * from bbb" 
    $result=mysql_query($sql);

    $inc=0;
    while(
    $row=mysql_fetch_array($result))
        {    
           
    $mat[$inc]=$row['mat'];
          
    // $isbn[$inc]=$row['isbn']; if i remove the comment it will produce an error
           
    $title[$inc]=mysql_real_escape_string($row['title']);
           
    $author[$inc]=mysql_real_escape_string($row['author']);
           
    $publisher[$inc]=mysql_real_escape_string($row['publisher']);
          
    $copyright[$inc]=$row['copyright'];
          
    $edition[$inc]=$row['edition'];
          
    $setcode[$inc]=$row['setcode'];
           
    $price[$inc]=$row['price'];

           
    $inc++;
        }
    This code will run if I commented one of the column to be fetch like this
    // $isbn[$inc]=$row['isbn'];Or If I set some limit. But if remove the comment or the limit it will produce an error why is that so?Is this memory limit of mysql or something?Both table has 90 thousand rows. How can I address this problem?
    Last edited by Anishgiri; 02-25-2013 at 09:58 AM.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    What exactly is the error?
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    My guess is you have the wrong title in your database

    $row['isbn']

    check isbn in your database
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This ^
    The error you are seeing is likely a notice that 'isbn' is not a valid offset in $row.

    These don't make any sense:
    PHP Code:
           $title[$inc]=mysql_real_escape_string($row['title']);
           
    $author[$inc]=mysql_real_escape_string($row['author']);
           
    $publisher[$inc]=mysql_real_escape_string($row['publisher']); 
    $row is extracted from the database; mysql_real_escape_string is designed to escape the strings to prevent SQL injection. They won't carry any value outside of it, but will corrupt the data should it contain characters that need to be escaped during insertion. So now a title with an ' in it would become \'.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    May 2010
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    This ^
    The error you are seeing is likely a notice that 'isbn' is not a valid offset in $row.

    These don't make any sense:
    PHP Code:
           $title[$inc]=mysql_real_escape_string($row['title']);
           
    $author[$inc]=mysql_real_escape_string($row['author']);
           
    $publisher[$inc]=mysql_real_escape_string($row['publisher']); 
    $row is extracted from the database; mysql_real_escape_string is designed to escape the strings to prevent SQL injection. They won't carry any value outside of it, but will corrupt the data should it contain characters that need to be escaped during insertion. So now a title with an ' in it would become \'.
    Yeah you are right. I don't know what I am thinking when I put that escape string. @Arcticwarrio and @ Fou Regarding the isbn it's actually a valid offset. If I remove the comment of isbn and commented another row for example //$edition[$inc]=$row['edition'], it will work. The thing is I need to comment any of this row for this to run(in this example I choose isbn). This is weird.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    So what is the error you are receiving? The only thing that really makes sense comment wise would be an undefined offset.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder
    Join Date
    May 2010
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    So what is the error you are receiving? The only thing that really makes sense comment wise would be an undefined offset.
    This the error.

    Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in /var/www/projection/projection/matdel_update2.php on line 40.

    I solved this with
    PHP Code:
    ini_set('memory_limit''-1'); 
    Last edited by Anishgiri; 02-26-2013 at 12:59 AM.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That's not exactly the best solution depending on the cause.
    As is, you have exhausted 128MB of ram. That is *a lot* of memory to go through PHP wise.
    Since we see nothing but text here, let us put this into perspective. If you were to select ~13,500 articles at 2,000 words per article (avg of 5 characters per word), that is about equivalent to 128MB of ram. Although its certainly possible to be selecting this much data and shoving it into arrays (PHP does not care about how much memory the external resource from the mysql is using), I'd be more inclined to believe there is an infinite loop condition or open resources to heavy memory processes such as the GD library.
    So you'll want to verify the cause of the ram usage before just allowing it free reign to unlimited memory usage. If you *need* that much ram is one thing, but if it shouldn't be using that much (as is the case in what you have posted here), that is an entirely different thing. Determine the cause, and go from there. All I can suggest with the code you have here is to issue where and limit controls on the queries.

    BTW, if you are on a shared host and you disable your memory limit and it causes problems, your host will most definitely cut your services off.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    rgb
    rgb is offline
    New Coder
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I've always understood that mysql_fetch_array() should always include a second argument, either MYSQL_NUM or MYSQL_ASSOC, because by default it outputs both the numerically indexed and the associatively indexed arrays.

    So, changing mysql_fetch_array( $result ) to mysql_fetch_array( $result, MYSQL_ASSOC ) should halve the amount of memory used.


    Is this possibly an issue here?

  • #10
    Regular Coder
    Join Date
    May 2010
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    That's not exactly the best solution depending on the cause.
    As is, you have exhausted 128MB of ram. That is *a lot* of memory to go through PHP wise.
    Since we see nothing but text here, let us put this into perspective. If you were to select ~13,500 articles at 2,000 words per article (avg of 5 characters per word), that is about equivalent to 128MB of ram. Although its certainly possible to be selecting this much data and shoving it into arrays (PHP does not care about how much memory the external resource from the mysql is using), I'd be more inclined to believe there is an infinite loop condition or open resources to heavy memory processes such as the GD library.
    So you'll want to verify the cause of the ram usage before just allowing it free reign to unlimited memory usage. If you *need* that much ram is one thing, but if it shouldn't be using that much (as is the case in what you have posted here), that is an entirely different thing. Determine the cause, and go from there. All I can suggest with the code you have here is to issue where and limit controls on the queries.

    BTW, if you are on a shared host and you disable your memory limit and it causes problems, your host will most definitely cut your services off.
    I want to clarify, so you are suggesting that there are other programs that uses lots of memory in the server that I use?

    @rgb- Yeah it seems using MYSQL_ASSOC with mysql_fetch_array is good idea.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by Anishgiri View Post
    I want to clarify, so you are suggesting that there are other programs that uses lots of memory in the server that I use?
    That depends. If you are on a dedicated physical server, than its whatever you have configured to run. With a database online, that is likely chewing through tons of memory alone.
    If you are on a shared host, its you plus everyone else. Shared hosts using a local dbms will require even more memory to support the db. And needless to say, shared hosts are known for over expending their resources.
    Unless you are expecting to handle in excess of 128MB of ram, than something is wrong. That's why I put some examples in to see what it takes to consume that much memory for normal operations. 12K+ 2000 word articles is a lot.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #12
    Regular Coder
    Join Date
    May 2010
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So let say I really have huge data. What is a good solution for this memory problem?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •