php - MySql PDO beginning a transaction and passing it to objects -


will work? i'd test don't know how crash things half way though.

$db = db::getdb(); try{     $db->begintransaction();     invoice::saveinvoice($info, $db);     invoicedetails::savedetails($moreinfo, $db);     $db->commit(); }catch(exception $e){     $db->rollback(); } 

and if work there bite me in butt besides doing causes implicit commit?

the thing i'd fix exception handling. example

catch (exception $e) {     $db->rollback();     throw $e; } 

doing lets safely rollback transaction letting error bubble further in application.

you wrap inner exception (which pdoexception) 1 of choosing, eg

$db->rollback(); throw new runtimeexception('error saving invoice details', 0, $e); 

to "crash things half way though", throw exception within 1 of save* methods, eg

throw new exception('ka-blam!'); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -