Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Last ID from a table
#2

[eluser]bretticus[/eluser]
If you are using MySQL and you dig under the hood a bit I'd suspect you'd find that insert_id probably utilizes mysql_insert_id and that PHP function makes use of the mysql_insert_id function that is native to MySQL. According to the MySQL manual:

Quote:For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.

Each page load or each time the browser requests a URI and the PHP code at that URI is executed, you have a client instance in context with the rest of the script being executed. In other words, mysql_insert_id should return the last query relative the instance in which it is running. Not another users instance of that same script.

In 10 years of PHP development, I cannot think of a single time that nearly simultaneous page loads stole a last insert id. I don't think you have cause for concern in this case.


Messages In This Thread
[SOLVED]Last ID from a table - by El Forum - 12-29-2009, 12:48 AM
[SOLVED]Last ID from a table - by El Forum - 12-29-2009, 01:05 AM
[SOLVED]Last ID from a table - by El Forum - 12-29-2009, 01:05 AM
[SOLVED]Last ID from a table - by El Forum - 12-29-2009, 02:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB