其他未缓冲的查询处于活动状态时,PDO无法执行查询 [英] PDO Cannot execute queries while other unbuffered queries are active

查看:98
本文介绍了其他未缓冲的查询处于活动状态时,PDO无法执行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这必须是一个简单的修复程序,而且我部分理解为什么我会收到此错误,但不知道如何解决它.我看了看文档,但除了使用缓冲查询选项外,找不到其他解决方案.我也尝试过,但是不起作用.

I know this has to be a simple fix and I partially understand why I am getting this error but don't know how to fix it. I've looked over the docs but can't find a solution other than using buffered queries option. I have tried that as well but it doesn't work.

错误是:在其他无缓冲查询处于活动状态时,PDO无法执行查询

The error is: PDO Cannot execute queries while other unbuffered queries are active

错误来自我构建$ result数组的行.

The error is coming from the line where I am building the $result array.

foreach($phones as $phone)
{
    $stmt = db::getInstance()->prepare("CALL phones(:phone)");
    $stmt->bindParam(':phone', $phone, PDO::PARAM_INT, 10);
    $stmt->execute();

    $result[] = db::getInstance()->query("SELECT @phone;")->fetchAll(PDO::FETCH_ASSOC);
}

推荐答案

您需要使用PDOStatement :: closeCursor()方法释放连接

You need to free up your connection using the PDOStatement::closeCursor() method

http://www.php.net/manual/en/pdostatement. closecursor.php

我相信

foreach($phones as $phone)
{
    $stmt = db::getInstance()->prepare("CALL phones(:phone)");
    $stmt->bindParam(':phone', $phone, PDO::PARAM_INT, 10);
    $stmt->execute();

    $stmt->closeCursor()

    $result[] = db::getInstance()->query("SELECT @phone;")->fetchAll(PDO::FETCH_ASSOC);
}

应该为您做

这篇关于其他未缓冲的查询处于活动状态时,PDO无法执行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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