Reputation: 107
Actually i've a server for get data to show to clients. I use :
But since few days, i've a PHP Error :
[28-Oct-2019 08:58:51 Europe/Paris] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in C:\wamp64\www\src\System\Doctrine.php on line 122
[28-Oct-2019 08:58:51 Europe/Paris] PHP 9. PDOStatement->fetchAll() C:\wamp64\www\src\System\Doctrine.php:122
I look on internet for resolve my issue, but I dont see anything helping me...
I already try to put memory_limit
to -1, but nothing change.
Here, you can see my line 122 of Doctrine.
public function getAllWhere($tableName, $refCol, $refVal) {
$r = $this->web->prepare("SELECT * FROM $tableName WHERE $refCol = :val");
$r->bindValue(':val', $refVal, PDO::PARAM_STR);
$r->execute();
$res = $r->fetchAll();
return $res;
}
In my database, inside the table, there is 1,500,000 rows.
I think the FetchAll
is guilty.
Finaly i've optimize my table & query, it was the best way.
Upvotes: 1
Views: 1354
Reputation: 246023
Obviously the query result set is too big to be contained in memory on the client.
Use a cursor:
DECLARE cur CURSOR FOR SELECT ...;
Then run this in a loop until no more results are returned:
FETCH NEXT 100 FROM cur;
The cursor definition and the FETCH
statements have to be performed in one transaction.
Upvotes: 1
Reputation: 1966
Update your php.ini at memory_limit directive.
put this in your php.ini
:
memory_limit=1024M
and restart the apache by this syntax or manually:
sudo systemctl restart httpd.service
Upvotes: 1