CodeIgniter Forums
Need some help on Transaction (Transaction didn't rollback) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Need some help on Transaction (Transaction didn't rollback) (/showthread.php?tid=80882)



Need some help on Transaction (Transaction didn't rollback) - jeffreyngai92 - 12-28-2021

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


RE: Need some help on Transaction (Transaction didn't rollback) - jeffreyngai92 - 12-28-2021

Hi All,


The problem Settle already
Is because of table engine problem should use InnoDB not MyISAM.


FYI You can use below code to check your database table engine type.


Code:
SELECT table_name, table_type, engine
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY table_name;


Thanks all.


RE: Need some help on Transaction (Transaction didn't rollback) - iRedds - 12-28-2021

Make sure your DBMS supports transactions.


RE: Need some help on Transaction (Transaction didn't rollback) - InsiteFX - 12-29-2021

MySQLi MyISAM supports transactions.


RE: Need some help on Transaction (Transaction didn't rollback) - iRedds - 12-29-2021

(12-29-2021, 01:31 AM)InsiteFX Wrote: MySQLi MyISAM supports transactions.
The manual says it does not support it.
https://dev.mysql.com/doc/refman/8.0/en/myisam-storage-engine.html


RE: Need some help on Transaction (Transaction didn't rollback) - InsiteFX - 12-30-2021

Ya your right I read all of the php.net on MySQLi and it says that you must use the InnoDB Engine.. Sorry about that.