本文介绍了使用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:
是唯一的查询
推荐答案
我遇到了相同的问题,但没有找到任何解决方法:
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无法执行查询,而其他无缓冲查询处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!