mysqli
e PDO
operam no modo buffer por padrão. Isso significa que suas consultas estão efetivamente sujeitas ao limite de memória do processo PHP.
De link :
[In buffered mode], query results are immediately transferred from the MySQL Server to PHP and are then kept in the memory of the PHP process. This allows additional operations like counting the number of rows, and moving (seeking) the current result pointer. It also allows issuing further queries on the same connection while working on the result set. The downside of the buffered mode is that larger result sets might require quite a lot memory.
Você deve aumentar o limite de memória dos processos PHP no seu php.ini
, aumentando a configuração memory_limit
ou pode dizer às consultas para usar o modo sem buffer :
Unbuffered MySQL queries execute the query and then return a resource while the data is still waiting on the MySQL server for being fetched. This uses less memory on the PHP-side, but can increase the load on the server.
Exemplo do Mysqli:
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$uresult = $mysqli->query("SELECT Name FROM City", MYSQLI_USE_RESULT);
Exemplo de PDO:
$pdo = new PDO("mysql:host=localhost;dbname=world", 'my_user', 'my_pass');
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);