Jeff Veit - Tanasity wrote:

If you have a MySQL db on Apache with mod php and you are using php with a
persistent connection, what happens when two people hit your webserver at
the same time? In particular, if the page runs an insert query on a table
with an auto_increment field what can happen to insert_id?

If you do the Insert and then immediately call insert_id, are you guaranteed
to get the relevant insert_id result? Or is it possible for the other page
(call it person_page_2) to get some execution time on the webserver, use the
same persistent connection and insert. If that can happen, then do you get
the right insert_id value back when person_page_1 resumes? Or do you get the
most recent, which would be the insert from person_page_2?

It's safe. The value returned by mysql_insert_id() is tied to your connection. So even if you do an insert and 100 other pages do insert before you call mysql_insert_id(), you'll still get your value and none of theirs, no matter how quickly it happens.

---John Holmes...

Amazon Wishlist:

PHP|Architect: A magazine for PHP Professionals –

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to