2015-01-07 67 views
2

好吧,我已經解決了,反正我不知道爲什麼它的工作...:PMySQL的「命令不同步」

我的第一個代碼是:

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

if([email protected]){ 
    $dbh->rollback; 
    warn [email protected]; 
}else{ 
    $dbh->commit; 
} 

它停止與MySQL錯誤「命令不同步」對犯下

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

if([email protected]){ 
    $dbh->rollback; 
    warn [email protected]; 
}else{ 
    $dbh->commit; 
} 

本地化$sth$rceval{}它的工作原理之後......爲什麼?

+3

'$ sth'添加的隱式'$ sth-> finish'超出範圍??? – ikegami

+1

看起來很像[DBI begin_work不能用於存儲過程調用](http://stackoverflow.com/q/6454840)中描述的問題。 [pilcrow's answer](http://stackoverflow.com/a/10001508/176646)是在提交事務之前顯式調用'$ sth-> finish()'(與@ikegami所說的一樣)。 – ThisSuitIsBlackNot

回答

0

ikegami的回答是正確的。

您需要調用$ sth-> finish(),這是隱式完成的,因爲它超出了eval {}塊的範圍。

相關問題