Edit report at https://bugs.php.net/bug.php?id=55003&edit=1
ID: 55003 Updated by: u...@php.net Reported by: jamesvl+php at gmail dot com Summary: PDO prepare() ignores MYSQL_ATTR_USE_BUFFERED_QUERY -Status: Open +Status: Feedback Type: Bug Package: PDO related Operating System: all PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: Please try using this snapshot: http://snaps.php.net/php5.4-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Previous Comments: ------------------------------------------------------------------------ [2011-06-06 20:15:09] jamesvl+php at gmail dot com Description: ------------ Steps to reproduce: Set up a database so a query can return ~ 10,000 rows - enough to bump memory usage to noticeable levels. Use PDO to prepare a query where you explicitly disable buffered queries: PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false. The PHP docs give an example of how to do this at http://www.php.net/manual/en/ref.pdo-mysql.php. Execute that statement. Use "memory_get_peak_usage()" to watch PHP memory usage for the script before and after the call to pdoStmt->execute(). Notes: Settings PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false when creating the PDO object *does* work as expected. (i.e. query buffering will be turned off or on; default is on if not specified) However, the PHP documentation makes it appear that an individual prepared statement should be able to change or override this settings for an individual query, which is not the case. PHP version tested: PHP 5.3.6 using mysqlnd, Win32 and Linux custom compile. Note that testing on PHP 5.2 (i.e. without mysqlnd) is not possible since mysqlib allocates memory outside of the PHP parser, and thus is not tracked by memory_get_peak_usage() and is not limited by php.ini memory_limit settings. Test script: --------------- if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $stmt = $this->db->prepare($qry, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false)); echo "\nmax bytes mem used: " . memory_get_peak_usage() . "\n"; $stmt->execute(); echo "max bytes mem used: " . memory_get_peak_usage() . "\n"; } Expected result: ---------------- Expect to see: Very little new memory allocated even when returning large result sets. Memory usage should *not* vary based on the result set size. ex: max bytes mem used: 700624 max bytes mem used: 700624 Actual result: -------------- Actually see: Memory usage increases directly with the size of the result set returned - PDO is using a buffered query. ex: max bytes mem used: 700240 max bytes mem used: 26291600 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55003&edit=1