使用PDO执行exec时,我得到2014无法执行查询,而其他无缓冲查询处于活动状态 [英] I get 2014 Cannot execute queries while other unbuffered queries are active when doing exec with PDO

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

问题描述

我正在多次更新中执行PDO::exec命令:

I am doing a PDO::exec command on multiple updates:

$MyPdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
$MyPdo->exec("update t1 set f1=1;update t2 set f1=2");

我正在交易中进行操作,并且不断出现以下错误:

I am doing it inside a transaction, and I keep getting the following error:

SQLSTATE [HY000]:一般错误:2014年 不能同时执行查询 无缓冲查询处于活动状态. 考虑使用 PDOStatement :: fetchAll(). 或者,如果您的代码仅 曾经要针对mysql运行,你 可以通过设置启用查询缓冲 PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY 属性.

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.

是唯一的查询

推荐答案

我遇到了相同的问题,但没有找到任何解决方法:

I encountered the same problem, and haven't found any solution:

$pdo->exec('update....;update...;')
$pdo->exec('update....;update...;')

在php 5.3之前,您可以通过销毁$ pdo来关闭连接,在php 5.3+中, 您可以使用$ pdo-> query()执行多查询, 注意$ pdo-> exec()完成并不意味着sql服务器完成了执行:

Before php 5.3 you could close connection by destroy $pdo, in php 5.3+, you could use $pdo->query() to execute multi-query, take care that $pdo->exec() finished does not mean the sql server finished the execution:

$cnt=1000;
$sql='';
$j=0;
for ($i=0;$i<$cnt;++$i)
    {++$j;
     $sql.="update sem_UploadKeywordQueue set ProductCount='{$i}' where ID='{$i}';";
     if ($j==100)
        {$pdo=new PDO('mysql:host=domain.com;port=3306;dbname=db', "user", "pass");
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $pdo->exec($sql);
         $pdo=null;
         $sql='';
         $j=0;
        }
    }
if ($sql)
   {$pdo->exec($sql);
   }

对于diyism

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

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