1 // 启动事务 2 Db::startTrans(); 3 try { 4 ????// 数据库操作 ?5 ????if (!Db::table(‘think_user‘)->delete(1)) { 6 ????????throw new Exception(‘删除数据失败!‘); //输出错误信息 7 ????} 8 // 提交事务 9 ????Db::commit();10 } catch (\Exception $e) {11 // 回滚事务 ?$e->getMessage();获取错误信息
12 Db::rollback();
13 }
ThinkPHP5 事务
原文地址:https://www.cnblogs.com/fbio/p/9169037.html