和Db开启事务类似,Db是静态方法
$userObj = new UserModel(); $userObj->startTrans(); try { $userObj->data($data,true)->isUpdate(false)->allowField(true)->save(); } catch(Exception $e) { $userObj->rollback(); Log::write('error:' . $e->getMessage() . ';行:' . $e->getLine() . ';文件:' . $e->getFile() . ';trace:' . $e->getTraceAsString(),'error'); }
$userObj->commit();