ZF2 已经处于活动状态的查询阻止执行 [英] ZF2 already active query prevents execution

查看:53
本文介绍了ZF2 已经处于活动状态的查询阻止执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在删除文件和数据库条目的函数中,我有类似以下内容:

I have something like the following, in a function that deletes both the files and db entries:

$adapter = $this->getAdapter();
$query = $adapter->query("call find_results_by_job_id(?)", array($jobId));
$items = array();
while (($current = $query->current()) !== false)
{
    $id = $current['id'];
    $items[] = $id;
    $query->next();
}
$this->deleteFromDataStore($items);
$result = $adapter->query("call delete_results_by_job_id(?)", array($jobId), \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);

(其中一些看起来可能不是最好的方法,因为我在此示例中对其进行了简化)

(Some of that might not look like the best way to do it, because I simplified it for this example)

我在最后一行收到此错误:SQLSTATE[HY000]:一般错误:2014 无法执行查询,而其他无缓冲查询处于活动状态.

I'm getting this error on the last line: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.

我假设问题是因为当我尝试执行另一个语句时,查询/适配器尚未关闭迭代结果的连接.如果是这种情况,如何重用适配器,或关闭查询,或者在最后一行之前我必须做的任何事情?

I'm assuming that the problem is because the query/adapter hasn't closed the connection from iterating results yet when I try to execute another statement. If that is the case, how can reuse the adapter, or close the query, or whatever I have to do before the last line?

奇怪的是,遵循几乎完全相同模式的代码在另一种方法中起作用.

The strange part is that code following almost exactly this same pattern works in another method.

答案:

使用PDO驱动时,$query->getDataSource()->getResource()->closeCursor();修复

When using the PDO driver, $query->getDataSource()->getResource()->closeCursor(); fixes it

推荐答案

似乎您正在使用 MySQL 中的无缓冲查询.

如果是这样,您将不得不打开缓冲或中断前一个似乎挂起的查询的执行?

If it is so, you will either have to turn buffering on or break execution of previous query which seems to hang?

类似$query->close()

如果 $queryStatementInterface 的实例,则有 getResource() 返回 mysqli_stmt 并且你可以调用 close() on

If $query is instance of StatementInterface, then there is getResource() which returns mysqli_stmt and you can call close() on it.

(合并最终解决方案)

如果它使用 PDO,你可以得到 PDOStatement 并调用 closeCursor()

In case it uses PDO, you can get PDOStatement and call closeCursor()

这篇关于ZF2 已经处于活动状态的查询阻止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆