<?php// 开启事务,ci框架$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("用户信息修改失败"); } if ($rs) { // 删除用户角色中间表中的对应id数据 重新插入 $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("改变原有的角色失败"); } if ($res) { if ($this->systems_model->db->trans_status() === false) { $this->systems_model->db->trans_rollback(); } else { $this->systems_model->db->trans_commit(); } getpower(true);// 修改成功后会更新登录者的用户权限 $this->systems_model->base_close(); outprintapijson(0, '修改成功'); } else { throw new exception("修改角色失败"); } }} catch (exception $e) { $this->systems_model->db->trans_rollback(); $this->systems_model->base_close(); $msg = $e->getmessage(); outprintapijson(1, $msg); exit;}
相关文章推荐:
php中命名空间这部分内容的详解
php如何使用curl接收post地址即创建一个接口的方法
以上就是ci框架下开启事务的代码分析的详细内容。
