CodeIgniter Forums
2 databases, 1 transaction? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: 2 databases, 1 transaction? (/showthread.php?tid=67348)



2 databases, 1 transaction? - DimCI - 02-13-2017

Hi all!

My question is simple may be- Can I do the following:

$this->db->trans_start()
add(edit, delete) a record in database#1,
load database#2,
change $active_group,
add(edit, delete) a record in database#2,
close connection to #2,
change $active_group back,
and, at last, finish with $this->db->trans_complete()
?

Is the $this->db->trans_status() result reliable in this case or not?

Thank you


RE: 2 databases, 1 transaction? - DimCI - 02-13-2017

Found the answer myself: " Transactions are isolated within a single "database"" http://stackoverflow.com/questions/2239810/multiple-database-and-transactions

Bad news Sad

Is there a method to synchronize 2 databases on the fly?


RE: 2 databases, 1 transaction? - qury - 02-13-2017

You can do the below though:

Code:
$db1 = $this->load->database('db1', TRUE);
$db2 = $this->load->database('db2', TRUE);

$db1->trans_start();
$db2->trans_start();

$db1->insert('table';$data_array);
$db2->insert('table';$data_array);

$db1->trans_complete();
$db2->trans_complete();