TP5 使用事物

 TP5 使用事物

//模型方法中
function  shiWu(){
    //开启事务
    $this->startTrans();
    // 进行相关的业务逻辑操作
    $data=['user'=>"Yuzsmc"];
    $userInfo=$this->insertGetId($data); // 保存用户信息
    if ($userInfo){
        // 提交事务
        $this->commit();
        return $userInfo; 
    }else{
        // 事务回滚
        $this->rollback(); 
    }
}

猜你喜欢

转载自blog.csdn.net/yuzsmc/article/details/82048968