ZF-11761: Mysqli adapter close previous statment

Description

Mysqli adapter not allow use multiple statment at the same time. Problematic code can be find here (Zend_Db_Adapter_Mysqli line 370):


    public function prepare($sql)
    {
        $this->_connect();
        if ($this->_stmt) {
            $this->_stmt->close();
        }
        $stmtClass = $this->_defaultStmtClass;
        if (!class_exists($stmtClass)) {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($stmtClass);
        }
        $stmt = new $stmtClass($this, $sql);
        if ($stmt === false) {
            return false;
        }
        $stmt->setFetchMode($this->_fetchMode);
        $this->_stmt = $stmt;
        return $stmt;
    }

Adapter store each statment and close it before creating new one.

Example: Lets assume that we have table Dogs (id, name) and Pets (id, name). Following code work only for 1 row in Dogs table.


$mysqli = Zend_Db::factory('Mysqli', array(...));
$dogsQuery = $mysqli
    ->select()
    ->from('Dogs', array('id', 'name'))
    ->query();

while ($row = $dogsQuery->fetch()) {
  $zend_db->insert('Pets', array('name' => $row['name']);
  }

Calling insert in while will close $dogsQuery statement. I cannot use fetchAll method because Dogs table is relay huge. Fetching all records cause memory_limit error.

Comments

No comments to display