CodeIgniter Forums
Transactions - 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: Transactions (/showthread.php?tid=90836)



Transactions - sunchaser - 05-11-2024

Hello, i would like to run some sql statements but, if there is any exception (not only Database Exception, but any exception like out of memory etc) i want the sql statements rolled back. 
I have a mysql database with all the tables on INNODB engine.
I made this code:

PHP Code:
$db = \Config\Database::connect();
 
$db->transBegin();

try { 
    $rc $model->execute(array($structure_id));
    $db->transCommit();
}
catch (\
Exception $e)
{
    $db->transRollback();
    log_message('debug''Exception: ' $e->getMessage());


In the function execute I am throwing an exception but the sql is commited and not rolled back. What am I doing wrong?

Thanks