PDO out of memory fix

If your having issues with large PDO query sizes in PHP and getting out of memory issues the solution is to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false

refer below example

<?php
$pdo = new PDO('mysql:host=127.0.0.1', 'foo', 'bar', array(
    PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
));
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

For whatever reason on certain system even small queries can bomb out - just add in this attribute and your queries should now run fine in PDO

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP, ReactJS, Tableau, AWS RedShift and Matillion ETL

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Leave a comment

Name Notify me of replies by email.