编码器事务测试失败


Codeigniter transaction testing failing

我是Codeigniter的新手,并试图按照以下官方指南在MYSQL数据库上实现Codeigniter DB事务

https://www.codeigniter.com/user_guide/database/transactions.html

在指南中,它建议为了启动测试模式,我需要将TRUE传递给trans_start函数,这应该回滚DB中的更改,但这并没有发生。我的查询正在提交。

这是我的代码

$data = array(
            'Name' => $this->input->post('name'),
            'Address' => $this->input->post('addr'),
            'IMEI' => $this->input->post('imei'),
            'DOB' => $this->input->post('dob'),
            'Maritial_Status' => $this->input->post('m_status'),
            'GCM_ID' => $this->input->post('gcm'),
            'Mobile' => $this->input->post('mobile'),
            'Snap' => $this->input->post('snap')
            );
        $this->db->trans_start(TRUE);
        $this->db->set('CreatedOn','NOW()', FALSE);
        $this->db->insert('registered_person', $data);
        $Person_ID_FK=$this->db->insert_id();
        $data1 = array(
            'Person_ID_FK' => $Person_ID_FK,
            'Name' => $this->input->post('r_name'),
            'Number' => $this->input->post('r_number'),
            'Relation' => $this->input->post('relation')
            );
        $this->db->insert('reg_per_emergency_contact', $data1);
        $this->db->set('Person_ID_FK', $Person_ID_FK); 
        $this->db->insert('location');
        $this->db->trans_complete();
        if($this->db->trans_status() === FALSE)
        {
            $resultArray= array('flag'=>10,'status'=>-1);
        }
        else
        {
            $resultArray= array('flag'=>10,'status'=>1,'Person_ID'=>$Person_ID_FK);
        }
        return $resultArray;

注:我的MYSQL表使用的是InnoDB引擎

任何帮助都会很感激。提前感谢

这个问题以前就存在,现在已经修复了。您可以为这个问题提供日志[1]。对于存档的目的,您可以使用另一种方法。

    if($this->db->trans_status() === FALSE)
        {
            $resultArray= array('flag'=>10,'status'=>-1);
        }
        else
        {
            $resultArray= array('flag'=>10,'status'=>1,'Person_ID'=>$Person_ID_FK);
        }
        $this->db->trans_rollback(); //Rollback. This will remove your data from the database.
        return $resultArray;

不建议使用$this->db->trans_off();

[1]。https://github.com/bcit-ci/CodeIgniter/issues/5