和laravel的事务相比吧,从简单上来说我更喜欢laravel封装的方式,而下面Thinkphp和原生的差不多
$submit = true; $model = M(); $model->startTrans(); // 开启事务 // 要执行的SQL $dels = M('children')->where(['gid' => $gid])->delete(); if(empty($dels)) $submit = false; $upds = M('adanduser')->where(['g_id' => $gid])->save(['addtype' => 7]); if(empty($upds)) $submit = false; if($submit === true){ $model->commit(); // 提交事务 $this->success('成功!'); }else{ $model->rollback(); // 回滚 $this->error('失败!'); }