57sy.com(隐身中 发表于 2015-12-29 22:16:44

CI事物问题

我现在使用事物是这样的。。。。。
我使用的是手动模式
我新建了一个model 比如 螣上图
   //测试事物处理
   function test_trans(){
                   $this->load->Model("api/M_test2");
                   $data = array(
                           'to_id'=>1
                   );
                   $this->db->trans_begin();
                  
          
                   $num = $this->M_test2->data();
                   if($num <= 0 ){
                           $this->db->trans_rollback();
                  echo "error111";
                  exit;
                   }
                  
                   $this->insert_one("{$this->table_}message11", $data);
                          
                          
                   $this->db->trans_complete();
                   if ($this->db->trans_status() === FALSE)
                {
                  $this->db->trans_rollback();
                  echo "error";
                }else{
                        $this->db->trans_commit();
                        echo "success";
                }
   }


M_test2.php

<?php

class M_test2 extends M_common {
    function __construct(){
      parent::__construct();
    }

   function data(){
                  $third_app = array(
                           'uid'=>444,
                           'idfa'=>'cccc' ,
                           'app_name'=>'cccc'
                   );
                   $result = $this->insert_one("{$this->table_}third_install_app", $third_app);
                   if($result['affect_num'] < 1){
            return false;
      }else{
            return $result['insert_id'];
      }
   }

}



M_common.php 我封装了一些常见的增删改查语句

现在我把数据的配置

[*]pconnect = true 那就是正常的
这个我怀疑不是CI的bug ,应该是数据库实例化,我上面继承了一个M_common文件 然后他又事例了一个数据库连接。。。。
不知道这样理解对不对
页: [1]
查看完整版本: CI事物问题