【发布时间】:2014-07-03 18:09:57
【问题描述】:
在 catch 子句中,我如何确定哪个准备好的语句导致了错误,以便我可以对其应用 debugDumpParams?请参见下面的示例。
$p1=db::db()->prepare("INSERT INTO t1 (a,b,c) VALUES (:a,:b,:c)");
$p2=db::db()->prepare("INSERT INTO t2 (a,b,c) VALUES (:a,:b,:c)");
try{
$data=array('a'=>1,'b'=>2,'c'=>3);
$p1->execute($data);
$p2->execute($data);
}
catch(PDOException $e){
//Display debugDumpParams() for the statement that caused the error
}
【问题讨论】:
-
注释掉,一次尝试一个
-
为每个单独的 try-catch
-
@cmorrissey。不理想,因为我想要所有查询的通用捕获。
-
@MarkM 是的,我可以,但它肯定会添加一堆代码。不知道是否有更好的解决方案。
-
可能有更好的方法 - 我不确定。但是如果你有一堆查询,你可以把它们放在一个循环中,
prepare和execute每个都有一个 try-catch。不会有更多代码。