Welcome Guest, Not a member yet? Register   Sign In
Unable to check transaction status if a transaction fails
#1

I have a model method that does various inserts into various tables, and so I have wrapped it in a transaction.

However, I am struggling to log my own errors if the transaction fails, due to never being able to check $this->db->trans_status() when a legitimate DB error occurs.

After completing the transaction, I am checking for the status, as outlined here: https://ellislab.com/codeigniter/user-gu...tions.html

But when a DB error occurs, for what ever reason (one that would cause the transaction to fail), my line where I check the status is never reached.

My code (simplified):

PHP Code:
$this->db->query('SIGNAL SQLSTATE \'45000\' SET MESSAGE_TEXT = \'Custom error\''); // this is to cause a DB error intentionally!

$this->db->trans_complete(); //complete the transaction, should rollback if anything fails right?

if($this->db->trans_status() === FALSE// This is never checked if a DB error occurs
{
 
   trigger_error("Commit failed"); // throw my own error, sadly never thrown :(
}
else
{
 
   return $object;

Reply


Messages In This Thread
Unable to check transaction status if a transaction fails - by mr_pablo - 12-16-2015, 09:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB