zoukankan      html  css  js  c++  java
  • PHP 简单的事务用法实例+(Exception 错误自定义;抛出:laraval实现)

     1 <?php
     2 
     3 namespace AppHttpControllers;
     4 
     5 use IlluminateHttpRequest;
     6 
     7 use IlluminateSupportFacadesDB;
     8 
     9 
    10 class ManayController extends Controller
    11 {
    12     public function index(){
    13 
    14         try {
    15 
    16             DB::beginTransaction();
    17 
    18             $res1 = DB::table('manay')->where('id', '1')->increment('manay', 200);
    19 
    20             $res2 = DB::table('manay')->where('id', '2')->decrement('manay', 200);
    21 
    22             if($res1==true && $res2==true){
    23 
    24                 DB::commit();
    25 
    26             }else{
    27 
    28                 $this->fun();
    29 
    30             }
    31 
    32         }catch (Exception $e1){
    33 
    34               echo "发生错误(代号:". $e1->getCode() . ")";
    35 
    36               echo $e1->getMessage();
    37 
    38              DB::rollBack();
    39 
    40 
    41 
    42         }
    43 
    44 
    45     }
    46 
    47     public function fun(){
    48 
    49          throw new Exception('有错误','300');
    50 
    51 
    52 
    53     }
    54 
    55 
    56 
    57 }
  • 相关阅读:
    正则表达式
    .net打印控件基本用法
    批处理
    dos命令
    网络散点
    华为路由器命令
    用eNSP模拟
    oracle PL/SQL语法基础
    路由
    docker redis shell
  • 原文地址:https://www.cnblogs.com/zhaoguiyuan/p/11208733.html
Copyright © 2011-2022 走看看