CodeIgniter Forums
Rollback all queries after unsaccessfull transaction - 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: Rollback all queries after unsaccessfull transaction (/showthread.php?tid=52251)



Rollback all queries after unsaccessfull transaction - El Forum - 06-03-2012

[eluser]levani[/eluser]
I have the following queries inside a transaction:

Code:
$this->db->trans_begin();
$query = $this->db->where('id', $user_id)->set('`points`', "`points` + $point", FALSE)->update('users');
$this->db->insert('logs', $logData);
if ($this->db->trans_status() === FALSE)
{
    $this->db->trans_rollback();
}
else
{
    $this->db->trans_commit();
}

The problem is that the second query is still executed even if the first one has failed. For example when I change the table name from 'users' to something else, of course the first query fails but is insert is still made. Is this the correct behavior of transaction?


Rollback all queries after unsaccessfull transaction - El Forum - 06-03-2012

[eluser]PhilTem[/eluser]
I don't have a solution, but an idea: What's the type of your second table? As far as I know only the InnoDB engine supports transactions. That may be why you can't roll it back if the table engine isn't InnoDB


Rollback all queries after unsaccessfull transaction - El Forum - 06-03-2012

[eluser]levani[/eluser]
[quote author="PhilTem" date="1338746638"]I don't have a solution, but an idea: What's the type of your second table? As far as I know only the InnoDB engine supports transactions. That may be why you can't roll it back if the table engine isn't InnoDB[/quote]

Thanks for reminding that. I checked it out and the type of the second table was MyISAM.