I have a php script that loads data from a database.
The table I am loading the data from is 50mb big, and the current php memory settings allow for 128mb – still I get the error message
Allowed memory size of 134217728 bytes exhausted (tried to allocate 6 bytes)
Some research has led me to changing the following in php.ini:
memory_limit = 128M
I changed it to -1, which according to the documentation will set it to infinite. To no avail.
Not only does it not makes sense that even if the query returned all of the 50mb, it should not complain since the limit is set to 128mb – strangely, the query I run does not even need much memory: when I echo it out and run it directly in the database, it only returns three rows. The query looks as follows:
SELECT * FROM table WHERE foreign_id=1
Does anyone know how to fix that problem? I would like to set the memory limit to infinite.
EDIT 1
First of all – does it matter that I run the script from my terminal, not from my browser?
Second, here is the php code:
//Connect to database
$user="root";
$databasePassword="password";
$host="127.0.0.1";
$database="primarydata";
$identifier=mysql_connect($host,$user,$databasePassword,true);
$db1=mysql_select_db($database);
//Select * from first table
$query="SELECT id,name,city,country FROM table1 WHERE id>=1 ORDER BY id ASC";
$result=mysql_query($query);
$datas=array();
while($row=mysql_fetch_object($result)) $datas[]=(object) $row;
//Loop through artists
for($i=0;$i<sizeof($datas);$i++){
for($j=$i+1;$j<sizeof($datas);$j++){
//This is where the problem occurs
$query="SELECT * FROM table2 WHERE data_id=".$datas[$i]->id;
}
}
Third, do I have to use “–enable-memory-limit'”?
Try:
When I insert millions of entries into a database (samples), then I had the same problem as you. This one helped.
EDIT: to add, using this is not recommended (only e.g. on localhost for examples as I gave you, entering tons of sample data into a database, etc.) This answer was posted before you posted your php code…