prepare('CALL mysp(?,?)');-6ren">
gpt4 book ai didi

MySQL "command out of sync"

转载 作者:行者123 更新时间:2023-11-29 03:32:53 25 4
gpt4 key购买 nike

好的,我已经修好了,反正我不知道为什么会这样...:P

我的第一个代码是:

my ($sth,$rc);
eval{
$sth = $dbh->prepare('CALL mysp(?,?)');
$rc = $sth->execute(1,2);
if ($rc eq '1'){# ok}
};

if($@){
$dbh->rollback;
warn $@;
}else{
$dbh->commit;
}

它在提交时因 mysql 错误“命令不同步”而停止

eval{
my $sth = $dbh->prepare('CALL mysp(?,?)');
my $rc = $sth->execute(1,2);
if($rc eq '1'){# ok}
};

if($@){
$dbh->rollback;
warn $@;
}else{
$dbh->commit;
}

在将 $sth$rc 本地化到 eval{} 后,它可以工作...为什么?

最佳答案

池上的回答是正确的。

您需要调用 $sth->finish(),这是隐式完成的,因为它超出了 eval{} block 的范围。

关于MySQL "command out of sync",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27829228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com