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'"?
phpinfo()show when you change the memory limit - maybe you are editing the wrong php.ini?MYSQLI_USE_RESULTin php.net/manual/en/mysqli.query.php. This is why it is taking up 50MB for the result set or more, as PHP is loading the entire result set into memory.