Codeigniter 3交易

时间:2016-01-29 06:36:50

标签: database codeigniter transactions

在我的代码中,即使我有数据库错误,事务也不会滚动....这里是代码...

即使在试用或注册中插入失败,登录用户也会插入数据......

$this->db->trans_start();
            $logindata = $this->_get_login_data();
            $logindata['is_deleted'] = 0;
            $this->db->insert('user_login',$logindata); 
            //insert login data end


            //insert register data begin
            $registerdata = $this->_get_register_data();
            $registerdata['is_active'] = 1;
            $registerdata['user_login_id'] = $this->db->insert_id();
            $registerdata['subscription_id'] = null;
            $registerdata['login_other_accounts_id'] = null;
            $registerdata['is_first_time_login'] = 1;
            $registerdata['default_language_id'] = 1;
            $registerdata['created_on'] = date('Y-m-d H:i:s');
            $registerdata['is_deleted'] = 0;

            //insert trial period begin
            $trialdata['trial_period_day'] = 10;
            $trialdata['is_publish'] = 0;
            $trialdata['is_deleted'] = null;
            $this->trial_period_model->insert('trial_period',$trialdata);
            //insert trial period end

            if($registerdata['is_company']==null)
                $registerdata['is_company'] = 0;
            $registerdata['trial_period_id'] = $this->user_model->get_last_inserted_id();
            $this->upload_image();
            $imagename = $this->upload->data();
            $registerdata['photo_logo'] = $imagename['file_name'];
            $this->user_model->insert('general_reg_info',$registerdata);
            if ($this->db->trans_status() === FALSE)
            {
                    $this->db->trans_rollback();
                    echo "failed";
            }
            else
            {
                    $this->db->trans_commit();
                    echo "success";
            }
            //insert register data end

1 个答案:

答案 0 :(得分:1)

您的数据库类型可能是'MyISAM'将数据库类型更改为'InnoDB'