Welcome Guest, Not a member yet? Register   Sign In
Need some help on Transaction (Transaction didn't rollback)
#1

(This post was last modified: 12-28-2021, 09:33 PM by jeffreyngai92.)

Dear all,

Sorry for my broken English.
I'm using codeigniter 4 and PHP 8.1.1
I tried below code in model and call in controller, (I turn off DBdebug)
the first query is correct and the second one I put wrong column name to test,
This is what I get in log: Unknown column 'mobile1' in 'field list'
And the first query still executed.
Code:
function testTransaction()
{
        $this->db->transStart();

        $builder = $this->db->table('sms_otp');
        $builder->insert(['mobile' => 12344, 'usage' => 1]);

        $builder = $this->db->table('sms_otp');
        $builder->insert(['mobile1' => 123555, 'usage' => 1]);

        $this->db->transComplete();
}

I'm using manual way
Code:
function testTransaction()
{
        $this->db->transBegin();

        $builder = $this->db->table('sms_otp');
        $builder->insert(['mobile' => 123444445, 'usage' => 0]);

        $builder = $this->db->table('sms_otp');
        $builder->insert(['mobile1' => 12344444, 'usage' => 0]);

        if ($this->db->transStatus() === false)
        {
            log_message('error', 'rollback ?');
            $this->db->transRollback();
        }
        else
        {
            $this->db->transCommit();
        }
}

Error message i get
ERROR - 2021-12-29 10:51:03 --> Unknown column 'mobile1' in 'field list'
ERROR - 2021-12-29 10:51:03 --> rollback ?

Please help, or any idea what I should check for.
Thanks
Reply


Messages In This Thread
Need some help on Transaction (Transaction didn't rollback) - by jeffreyngai92 - 12-28-2021, 07:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB