4

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?

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Next error occured: 'Fatal error: Call to undefined method database::setAttribute() in /var/www/flunky/backend.php on line 38' I used it with my $db variable '$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $db->query('SELECT * FROM teams'); $teams = $db->resultset(); print_r($teams);'
you tagged your question with PDO, so I provided solution for PDO
Yeah and it is PDO, or not? why does he called it an "undefined method"?
because your "database" is anything but PDO
Shouldn't it be false for unbuffered queries? Or how is this going to fix the memmory issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.