开发者

Store LAST_INSERT_ID() in a transaction

开发者 https://www.devze.com 2023-01-02 06:36 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号