how to use transactions in codeigniter for commit and rollback based on data change?
Use the following steps.
1.Begin your transaction using $this->db->trans_begin();
.
2.Performs queries.
3.Check Transaction status using $this->db->trans_status()
.
4.If status
is true commit
transaction using $this->db->trans_commit();
.
5.If status
is false rollback
transaction using $this->db->trans_rollback();
.
$this->db->trans_begin();$this->db->query('AN SQL QUERY...');$this->db->query('ANOTHER QUERY...');$this->db->query('AND YET ANOTHER QUERY...');if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback();}else{ $this->db->trans_commit();}
For more see docs Codeigniter Transaction