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