【发布时间】:2015-03-05 22:11:11
【问题描述】:
好的,我已经修好了,反正我不知道为什么会这样……: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添加$sth超出范围??? -
看起来很像DBI begin_work doesn't work with stored procedure calls 中描述的问题。 pilcrow's answer 是在提交事务之前显式调用
$sth->finish()(与@ikegami 所说的一致)。