用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
>[danger] Db类 事务操作示例 ``` use think\facade\Db; ``` ``` // 启动事务 Db::startTrans(); try { Db::table('think_user')->find(1); Db::table('think_user')->delete(1); // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); // 事务执行中有错误 die('错误信息: ' . $e->getMessage()); } ``` >[danger] 使用模型 操作事务 + `fault()` 是我封装的用于抛出异常的函数 ``` $model = new User; // $model = User::findOrEmpty($id); // $model->isEmpty() && fault('数据不存在'); // 启动事务 $model->startTrans(); try { // 数据操作 // .... // 提交事务 $model->commit(); } catch (\Exception $e) { // 回滚事务 $model->rollback(); fault('操作失败'); } ```