Browse Source

Merge pull request #10139 from cakephp/fix-unbuffered-exception

Correctly re-setting the buffered statement setting for MySQL
Mark Story 9 years ago
parent
commit
875b454cd0
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/Database/Statement/MysqlStatement.php

+ 8 - 3
src/Database/Statement/MysqlStatement.php

@@ -32,9 +32,14 @@ class MysqlStatement extends PDOStatement
      */
     public function execute($params = null)
     {
-        $this->_driver->connection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $this->_bufferResults);
-        $result = $this->_statement->execute($params);
-        $this->_driver->connection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+        $connection = $this->_driver->connection();
+
+        try {
+            $connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $this->_bufferResults);
+            $result = $this->_statement->execute($params);
+        } finally {
+            $connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+        }
 
         return $result;
     }