try { $pdo->begintransaction (); foreach ($sql _arr as $sql) { $stmt = $pdo->exec ($sql); } $pdo->commit (); return true;} catch (Exception $e) { echo $e->getmessage (); $pdo->rollback (); return false;}
Above Please be familiar with the great God to help explain, in the PHP language, if there is a return in the try Catch statement, what is the order of execution?
Above this code, want is: PDO thing normal run return true, if have an exception return false, can I ask if the normal implementation?
Reply to discussion (solution)
This is what you write: normal run returns TRUE if an exception returns false
But be sure to set the property entry Pdo::attr_errmode to Pdo::errmode_exception
Otherwise, exception handling is not valid
And also
Exception $e
To write
Pdoexception $e
There's a lot of trouble!
Moderator greatly has answered, I come to mix, a small example
$res =test (' oo '), if ($res) {echo ' hehe ';} function test ($name) {try{a ($name); return true;} catch (Exception $e) {echo $e->getmessage (); return false;}} function A ($name) {if ($name = = "xx") {return true;} Else{throw New Exception ("Error");}}
This is what you write: normal run returns TRUE if an exception returns false
But be sure to set the property entry Pdo::attr_errmode to Pdo::errmode_exception
Otherwise, exception handling is not valid
And also
Exception $e
To write
Pdoexception $e
There's a lot of trouble!
Thank!