Re: Is persistent connection + MySQL + Apache + insert_id === safe?

From: Date: Mon, 14 Jul 2003 12:04:09 +0000
Subject: Re: Is persistent connection + MySQL + Apache + insert_id === safe?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29227@lists.php.net to get a copy of this message
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: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com

« previous php.db (#29227) next »