• CI框架--事务


    CI框架中事务封装的很完善,使用起来很简单

    1.不开启事务

    //不开启事务  前两个sql 能够执行成功,第三个执行失败
    $this->device_model->addForCamera(1, '爱三123', '2016122903', 0);
    $this->device_model->setStateInDevices(1, array(2));
    $this->device_model->addForCamera(1, '爱三1234567890', '2016122903', 0);
    

    2.自动事务

    //失败自动回滚
    $this->db->trans_start();
    //三条sql 都执行失败
    $this->device_model->addForCamera(1, '爱三123', '2016122903', 0);
    $this->device_model->setStateInDevices(1, array(2));
    $this->device_model->addForCamera(1, '爱三1234567890', '2016122903', 0);
    
    $this->db->trans_complete();
    

    3.手动事务

    //若失败手动回滚 成功手动提交
    $this->db->trans_begin();
    
    //三条sql 都执行失败
    $this->device_model->addForCamera(1, '爱三123', '2016122903', 0);
    $this->device_model->setStateInDevices(1, array(2));
    $this->device_model->addForCamera(1, '爱三1234567890', '2016122903', 0);
    
    if ($this->db->trans_status() === false) {
        $this->db->trans_rollback();
    } else {
        $this->db->trans_commit();
    }
         
    

      

      

  • 相关阅读:
    P1168 中位数(对顶堆)
    P2341 [HAOI2006]受欢迎的牛
    P1967 货车运输
    树状数组的神操作QAQ
    P1063 能量项链
    P1429 平面最近点对(加强版)
    P2571 [SCOI2010]传送带
    4 Values whose Sum is 0
    UVA529 Addition Chains
    UVA307 Sticks
  • 原文地址:https://www.cnblogs.com/zc123/p/6233048.html
Copyright © 2020-2023  润新知