Codeigniter one transaction with two model Codeigniter one transaction with two model codeigniter codeigniter

Codeigniter one transaction with two model


As long as you don't have other transaction statements in your model methods, your sample code should work fine.

As per the documentation, you can test it by passing TRUE to $this->db->trans_start():

$this->db->trans_start(TRUE);// Queries/model calls$this->db->trans_complete();if($this->db->trans_status() === FALSE){    // do something if it fails}

Passing TRUE to trans_start() will automatically rollback the transaction upon completion. You should be able to check auto_increment values on your tables (if applicable) to see if the transaction worked or not.