Operation Codeigniter

How does a transaction work in CodeIgniter? can i stop the transaction and start each other?

See my example

$this->db->trans_begin(); $a = 'UPDATE ......'; RETURN TRUE $b = 'INSERT INTO......'; RETURN FALSE $this->db->trans_rollback(); // I tried $this->db->trans_off(); var_dump( $this->db->trans_status() ); $this->db->trans_begin(); if ( $this->db->trans_status() === FALSE ) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); } 

My first transaction will always return FALSE (even if this is true, I need to roll it back), now I need to close this transaction and start it again.

The problem is $this->db->trans_status() , it always returns FALSE in the second transaction (even after $this->db->trans_rollback() or trans_off() ).

what am I doing wrong? Please help me.

 I am using mySql as underlying database. 
+4
source share
2 answers

Now it works fine by manually setting trans_status

 $this->db->trans_begin(); $a = 'UPDATE ......'; RETURN TRUE $b = 'INSERT INTO......'; RETURN FALSE $this->db->trans_rollback(); //First transaction ends it will return FALSE always(in my case) $this->db->_trans_status = TRUE; // setting the trans_status manually ,so it will ignore previous attempts $this->db->trans_begin(); //other operations .. if ( $this->db->trans_status() === FALSE ) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); } 
+1
source

I think you need to add this before the start of the transaction:

 $this->db->trans_strict(FALSE); 

By default, CodeIgniter launches all transactions in strict mode.

If strict mode is enabled, if you use multiple transaction groups, if one group fails, all groups will be thrown back.

+1
source

All Articles