您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

CI框架下开启事务的代码分析

2025/9/19 18:15:38发布20次查看
这篇文章给大家介绍的内容是关于ci框架下开启事务的代码分析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
<?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框架下开启事务的代码分析的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product