TP5.0 事务操作

    if(request()->isPost()){
           $goodName = input('post.goodName');
            Db::startTrans();
            try{
                Db::name('goods_area')->insert(['areaName'=>$goodName]);
                Db::commit();   
            }catch(\Exception $e){
                Db::rollback();
                $this->error('添加货物地区失败,请重试');
            }   
            $this->success('添加货物地区成功','goods/goods_area'); //$this-success放在最外面,不然会认为有报错回滚
    }else{
           return $this->fetch('add_goods_area');
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章