首页> 实战笔录 >PHP开发笔记 >ThinkPHP ThinkPHP
TP5 模型事务操作
作者:小萝卜 2019-11-21 【 TP5 】 浏览 3591
简介注意:数据只要涉及多表一致性操作,必须要开启数据库事务操作,ThinkPHP5 中模型层中使用事务:
注意:数据只要涉及多表一致性操作,必须要开启数据库事务操作
ThinkPHP5 中模型层中使用事务:
try{
$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();
return ['code'=>'1008','msg'=>'商品订单添加失败','data'];
}
原文:https://www.kancloud.cn/mikkle/thinkphp5_study/557903
很赞哦! (1)
相关文章
- TP6 databackup拓展插件,实现数据库备份下载还原代码分享
- PHPExcel在TP3.2下使用方法
- tp6错误提示怎么不显示多少行了?
- TP5.0 给图片加文字水印怎么控制文字的透明度
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Attr_id' in 'where clause'
- PHP/TP5使用supervisor/workerman在CLI模式下mysql断线重连解决办法
- TP6使用redis操作报错Store [redis] not found.
- TP6 Validate内置验证规则总览
- TP3.2模板内使用U方法详细介绍
- TP5 添加平铺文字水印,并设置文字之间的间距和文字的角度
