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



Transaction - pippuccio76 - 09-16-2021

Hi sorry for english , can i insert in a transaction a simple method instead of db statement ? 
For example i want rollback if a mail was not been send...


RE: Transaction - includebeer - 09-19-2021

Yes you can do commit or rollback manually. Read this: http://codeigniter.com/user_guide/database/transactions.html#running-transactions-manually
PHP Code:
$this->db->transBegin();

$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');

if (
$this->db->transStatus() === false) {
    $this->db->transRollback();
} else {
    $this->db->transCommit();