用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1224|回复: 0
收起左侧

CI事物问题

[复制链接]
发表于 2015-12-29 22:16:44 | 显示全部楼层 |阅读模式
我现在使用事物是这样的。。。。。
我使用的是手动模式
我新建了一个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";
                }
   }

[/code]
M_test2.php
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文件 然后他又事例了一个数据库连接。。。。
不知道这样理解对不对

本版积分规则