• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Force database transaction rollback

#2
Wouldn't it be simpler to add a trans_force_rollback() or trans_fail() method to your DB driver which simply sets $this->_trans_status to false?

This would also lend itself to better exception handling under PHP 5.5+ by using a finally block to run trans_complete() with the trans_force_rollback() call in the catch block.

Personally, though, I tend to shy away from making a database transaction dependent on outside forces. A database transaction is intended to ensure a series of database actions are completed as a group (usually in part to ensure some integrity of the data), so the failure of one database action forces the rollback of previous actions in the transaction. Whether an email was sent is something I would normally indicate with a value in the database so I could simply attempt to re-send the email at another time (and/or not allow some other action to occur until the email is sent), as there are too many unrelated factors which can cause the email to fail.
Reply


Messages In This Thread
Force database transaction rollback - by beng - 03-05-2015, 07:34 AM
RE: Force database transaction rollback - by mwhitney - 03-05-2015, 11:01 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.