Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PDO query returns memory-size error

I tried to make a simple pdo request to select all values of a table

<?php public function query($query) { $this->stmt = $this->query($query); } ?>

But when I call it like

$db->query('SELECT * FROM teams'); $teams = $db->resultset(); print_r($teams);

an error occured

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 65484 bytes) in /var/www/flunky/functions/mysql.class.php on line 29

I tried to increase the memory size in php.ini and with ini_set('memory_limit', '512M');, but it doesn´t work. Can anybody help me?

like image 993
sydev Avatar asked Dec 06 '22 02:12

sydev


1 Answers

Run this code before running a query

$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

Further reading Buffered and Unbuffered queries

I tried to increase the memory size in php.ini and with ini_set('memory_limit', '512M');, but it doesn´t work.

It worked, actually.

The error message says that this exact amount were exhausted.

like image 135
Your Common Sense Avatar answered Dec 17 '22 19:12

Your Common Sense