Welcome Guest, Not a member yet? Register   Sign In
Code igniter transaction don't rollback on SQL error

Hi there,

today i've encountered a curious behaviour using CI transactions, calling a series of update queryies.

The strange thing is that the transaction not rollback when one of queryies return a sql error, (like an unexcistent field in a table), the other queryies  before the one that is throwing the error are executed normally.

The only thing i see is a sql error on screen.

my code is similar to this:




echo ($this->db->trans_status === false) ? 'Rollback' : 'Ok';

Thank you

Someone knows why it not rollback as expected?

You should be using an if else statement to check for an error.

PHP Code:
if ($this->db->trans_status() === FALSE)

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 05-04-2017, 05:48 AM by Esthar.)

But standing to the documentation, if i use $this->db->trans_start() & $this->db->trans_complete(), the queryies will rollback automatically when one of those fail.

Why my records are affected the same when one query fails?

I've noticed the engine of the table affected by the transaction was MyIsam, and than i changed it to InnoDB, ( because MyIsam not support transactions), but the results are the same. The queryies never rollback on a failure state.

Theme © iAndrew 2016 - Forum software by © MyBB