简体   繁体   中英

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 first 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM