Question

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 ?

Was it helpful?

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 :(

OTHER TIPS

I have solved in this way:

$sql = "
    SET FOREIGN_KEY_CHECKS = 0;
    TRUNCATE TABLE `customer`;
    TRUNCATE TABLE `customer_address`;
    TRUNCATE TABLE `customer_contact`;
    SET FOREIGN_KEY_CHECKS = 1;
    ";

$result = $this->adapter->query($sql)->execute();
$result->getResource()->closeCursor();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top