You can do it in the following way:
$this->db->trans_begin();
$this->db->query('SQL QUERY...');
$this->db->query('OTRA QUERY...');
$this->db->query('OTRA QUERY...');
if ($this->db->trans_status() === FALSE){
$this->db->trans_rollback();
}else{
$this->db->trans_commit();
}
You use $this->db->trans_begin();
to start the transaction.
You conduct the consultations.
Verify the status of the transaction using $this->db->trans_status();
.
If the Status
is TRUE
you confirm using $this->db->trans_commit();
.
If the Status
is FALSE
you cancel using $this->db->trans_rollback();
.
Basically this is a manual transaction, but Traditionally, the
transactions have required a good amount of work for their
implementation, since they require you to keep track of your
consultations and determine whether to commit or retract according to
of the success or failure of your consultations. This is particularly
uncomfortable in the case of nested queries. On the contrary, it
I implement an intelligent transaction system that does all this
by you automatically (you can also manage your transactions
manually if you wish, but in reality there is no
benefit).
Reference: Codeigniter Transaction