CodeIgniter Forums
Database Transaction Error Handling - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database Transaction Error Handling (/showthread.php?tid=21598)



Database Transaction Error Handling - El Forum - 08-14-2009

[eluser]Unknown[/eluser]
I have a lengthy script that is responsible for making many DB changes that are all required to complete for the operation to be successful, so I've wrapped them in a transaction. This script is also responsible for authorizing a payment before any database changes occur, and then capturing and actually charging the account after the changes are complete. I've included a check on $this->db->trans_status() === FALSE to see if the transaction failed, and if so then void the previously authorized payment, return errors to the user, etc. The problem I'm having is that say, for example, query 4 of 12 fails. The transaction is rolled back as it should, and I get the CI database error page displayed. The payment however is never voided, so it seems to me that as soon as the error occurs the script execution stops and it never gets to my trans_status check. I'm thinking that the only way to fix this is to check trans_status() after each and every call to the database, which seems kind of messy. Does anyone have a better way of handling this kind of process?