确定哪个预准备语句在try / catch中导致错误

In the catch clause, how do I determine which prepared statement caused the error so that I could apply debugDumpParams on it? See the below example.

$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
}

To determine which query fails execute them in different try catch blocks.

$data=array('a'=>1,'b'=>2,'c'=>3);

$p1 = db::db()->prepare("INSERT INTO t1 (a,b,c) VALUES (:a,:b,:c)");
try {    
    $p1->execute($data);
} catch(PDOException $e) {
    // Display debugDumpParams() for the statement that caused the error
    // First query has failed
}
$p2 = db::db()->prepare("INSERT INTO t2 (a,b,c) VALUES (:a,:b,:c)");
try {    
    $p2->execute($data);
} catch(PDOException $e) {
    // Display debugDumpParams() for the statement that caused the error
    // Second query has failed
}

You could check error code of each statement. (read documentation about codes of your DB). null means that statement was not executed.

If you are going to catch PDOException you might as well include prepare() in the try catch, and you should also use one query to inserts if possible.

Prepare returns false when it fails so check the value of $p and throw exception