laravle 事务

时间:2019-05-28 17:30:13   收藏:0   阅读:153

DB::beginTransaction();

try{
    $name ‘abc‘;
    $result1 = Test::create([‘name‘=>$name]);
    if (!$result1) {
        /**
         * Exception类接收的参数
         * $message = "", $code = 0, Exception $previous = null
         */
        throw new \Exception("1");
    }
    $result2 = Test::create([‘name‘=>$name]);
    if (!$result2) {
        throw new \Exception("2");
    }
    DB::commit();
catch (\Exception $e){
    DB::rollback();//事务回滚
    echo $e->getMessage();
    echo $e->getCode();
}

原文:https://www.cnblogs.com/simadongyang/p/10938618.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!