Search code examples
mysqlpdozend-framework2unbuffered

ZF2 PDO unbuffered queries


I have a install method for my cms witch reads sql files and executes them . so far so good .. But i also need to do some initialization on db ( inserting some dynamic values )

    $q = "INSERT INTO `tbl_users_roles` (`userId`, `roleId`) VALUES
            (1,3),
            (2,4);";
    $db->query($q, Adapter::QUERY_MODE_EXECUTE);

    $q = "INSERT INTO `tbl_users` (`username`, `password`, `accountStatus`) VALUES
            ('serverAdmin',?,1),
            ('admin',?,1);";
    $db->query($q, array($passAdmin, $passUser));

these inserts gets executed but the next sql file throws a exception :

PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

ZF2 PDO statement dose not have fetchAll or closeCursor. so how to fix this ?


Solution

  • ok i changed the last query to :

        $st = $db->query($q);
        $st->execute(array(serialize($perm)))->getResource()->closeCursor();
    

    this works but dose other db drivers have closeCursor too? there should be a generic way to do this :(