CodeIgniter Forums
it is save use $this->db->insert_id() ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: it is save use $this->db->insert_id() ? (/showthread.php?tid=57789)



it is save use $this->db->insert_id() ? - El Forum - 04-11-2013

[eluser]atoleon[/eluser]
I need to insert a new item in my database, but i need to get the id of this item inmediatelly.
I have seen the $this->db->insert_id() function, but i dont know if is it save use it.
what would happen if userA insert an item and before execute the insert_id() funcion, an userB insert another item. It is possible if there are a lot of users writing at the same time.

thank you


it is save use $this->db->insert_id() ? - El Forum - 04-11-2013

[eluser]TheFuzzy0ne[/eluser]
Yes, it's safe to use. $this->db->insert_id() will return the insert ID of the last inserted row by the currently executing script. It is not affected by other requests.


it is save use $this->db->insert_id() ? - El Forum - 04-11-2013

[eluser]atoleon[/eluser]
Thank you