CodeIgniter Forums
Transaction on two db - 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 on two db (/showthread.php?tid=89695)



Transaction on two db - pippuccio76 - 02-09-2024

hi , to do transaction i use this code 

[/CODE]
                    $db = \Config\Database::connect();

                    $db->transStart();
                             //CODE
                   $db->transComplete();


                    if($db->transStatus()!==false) {

                        //CODE show message ok

                    }else{

                         //CODE show message error
                    }

[/CODE]

I must copy value from one table's db (on same server ) to another db table from another db
  • truncate table dbA_tableMaterial
  • SELECT * FROM table dbB_tableMaterial
  • foreach value of mysql select insert value on table dbA_tableMaterial
It's possble use transaction ?


RE: Transaction on two db - InsiteFX - 02-09-2024

Not positive but maybe nested transactions.

CodeIgniter 4 User Guide - Transactions - Nested Transactions


RE: Transaction on two db - kenjis - 02-09-2024

See https://stackoverflow.com/questions/3399657/select-insert-across-multiple-databases-with-mysql