Store LAST_INSERT_ID() in a transaction
I use codeigniter's database abstarction, and im doing a transaction with it. My problem is, that i have several inserts into several tables, but i need the insert id from the f开发者_如何学JAVAirst insert query. Is there any way to store the last insert id for more than one following insert?
I don't understand why, but the ci built in function does not work.
Just grab the insert_id right after you do the queries...
$this->db->insert('table1', $data);
$insert_id1 = $this->db->insert_id();
$this->db->insert('table2', $data);
$insert_id2 = $this->db->insert_id();
$this->db->insert('table3', $data);
$insert_id3 = $this->db->insert_id();
Its the simplest way to do it.
精彩评论