Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2013, 07:20 AM   PM User | #1
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
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..
Anishgiri is offline   Reply With Quote
Old 02-25-2013, 10:54 AM   PM User | #2
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
What exactly is the error?
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 02-25-2013, 01:53 PM   PM User | #3
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 583
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
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.
Arcticwarrio is offline   Reply With Quote
Old 02-25-2013, 02:29 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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 \'.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-25-2013, 09:14 PM   PM User | #5
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
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.
Anishgiri is offline   Reply With Quote
Old 02-25-2013, 10:30 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
So what is the error you are receiving? The only thing that really makes sense comment wise would be an undefined offset.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-26-2013, 12:40 AM   PM User | #7
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
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..
Anishgiri is offline   Reply With Quote
Old 02-26-2013, 02:24 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-26-2013, 11:07 AM   PM User | #9
rgb
New Coder

 
Join Date: Jul 2011
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
rgb is an unknown quantity at this point
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?
rgb is offline   Reply With Quote
Old 02-27-2013, 01:09 AM   PM User | #10
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
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.
Anishgiri is offline   Reply With Quote
Old 02-27-2013, 03:12 AM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-27-2013, 03:28 AM   PM User | #12
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
So let say I really have huge data. What is a good solution for this memory problem?
Anishgiri is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:02 AM.


Advertisement
Log in to turn off these ads.