![]() |
Question about ActiveRecords - mysql_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: Question about ActiveRecords - mysql_insert_id() (/showthread.php?tid=32897) |
Question about ActiveRecords - mysql_insert_id() - El Forum - 08-09-2010 [eluser]Harshadewa[/eluser] In a multi-user environment, if we use $this->db->insert_id() (CodeIgniter ActiveRecord) to retrieve the id value of last inserted row, is there a chance of getting an ID of a different db session? According to the MySQL spec, they say; "The value of mysql_insert_id() is affected only by statements issued within the current client connection. It is not affected by statements issued by other clients." So, is it same with the CodeIgniter's ActiveRecord $this->db->insert_id() ? Is there a chance of 2 or more users who are inserting records to the same table, would get wrong last insert id's? Does CodeIgniter Active Records maintain unique db sessions for its concurrent users? Question about ActiveRecords - mysql_insert_id() - El Forum - 08-09-2010 [eluser]mddd[/eluser] Yes this is the same because CodeIgniter uses the mysql functions in the background. Besides, the Mysql server will not give you an id that was inserted for another connection than your own. So you can safely use this. It will never give you 'some one else's' id. Question about ActiveRecords - mysql_insert_id() - El Forum - 08-09-2010 [eluser]Harshadewa[/eluser] mddd, Thank you for the reply! |