This article introduces to you the content of the CI framework to open the transaction code analysis, there is a certain reference value, the need for friends can refer to, I hope you have some help.
<?php//open transaction, CI framework $this->systems_model->base_connect (); $this->systems_model->db->initialize (); $this->systems_model->db->trans_begin (); try {$rs = $this->systems_model->update ($data, $condition, ' User ', false); if (! $rs) {throw new Exception ("User Information modification failed"); } if ($rs) {//delete the corresponding ID data in the User Role intermediate table is reinserted $delRes = $this->systems_model->delete_user_role ($id ); if ($delRes) {foreach ($roles as $k = + $v) {$roleData [' iuserid '] = $id; $roleData [' sroleid '] = $v; $res = $this->systems_model->save ($act, $roleData, ' User_role ', false); }} else {throw new Exception ("Change the original role failed"); if ($res) {if ($this->systems_model->db->trans_status () = = = FALSE) {$this-&G T Systems_model->db->trans_rollback (); } else {$this->systems_model->db->trans_comMIT (); } getpower (TRUE);//The user rights of the login will be updated after the successful modification $this->systems_model->base_close (); Outprintapijson (0, ' modified successfully '); } else {throw new Exception ("Modify role failed"); }}} catch (Exception $e) {$this->systems_model->db->trans_rollback (); $this->systems_model->base_close (); $msg = $e->getmessage (); Outprintapijson (1, $msg); Exit;}