TP5模型事务操作

歌从心底唱起TP5模型事务操作
注意:数据只要涉及多表⼀致性操作,必须要开启数据库事务操作
ThinkPHP5 中模型层中使⽤事务:
try{
komda$this->startTrans();
$this->data($order_data)->isUpdate(false)->save();
$new_order = $this->order_no;
if (!is_numeric($new_order)) throw new \Exception("商品订单添加失败");大家来碴
$this->hasMany('OrdersAccess', 'order_no', 'order_no')->saveAll($data_order);
$this->commit();
辜鸿鸣return ['code' => '1001', 'msg' => '商品订单添加成功', 'data' => ['order_no' => $new_order, 'cart_list' => $data_order]];
国民经济核算论文
}catch (\Exception$e){
$this->rollback();
tebreturn ['code'=>'1008','msg'=>'商品订单添加失败','data'];
}

本文发布于:2024-09-22 09:55:35,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/153070.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:操作   事务   涉及
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议