我有一个安装方法,用于我的 cms 女巫读取 sql 文件并执行它们。到目前为止一切顺利..但我还需要对数据库进行一些初始化(插入一些动态值)
$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));
这些插入被执行,但下一个 sql 文件抛出异常:
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 语句没有 fetchAll 或 closeCursor。那么如何解决这个问题?