From: Operating system: all PHP version: 5.3.6 Package: PDO related Bug Type: Bug Bug description:PDO prepare() ignores MYSQL_ATTR_USE_BUFFERED_QUERY
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 bug report at http://bugs.php.net/bug.php?id=55003&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=55003&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=55003&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=55003&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=55003&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=55003&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=55003&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=55003&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=55003&r=needscript Try newer version: http://bugs.php.net/fix.php?id=55003&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=55003&r=support Expected behavior: http://bugs.php.net/fix.php?id=55003&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=55003&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=55003&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=55003&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=55003&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=55003&r=dst IIS Stability: http://bugs.php.net/fix.php?id=55003&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=55003&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=55003&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=55003&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=55003&r=mysqlcfg
