RE: [PHP] Auto-increment value

From: Date: Wed, 18 Sep 2002 13:00:12 +0000
Subject: RE: [PHP] Auto-increment value
Groups: php.general 
Request: Send a blank email to php-general+get-116733@lists.php.net to get a copy of this message
If there is a possibilty of that then BEGIN INSERT ... whatever SELECT idno ORDER BY (idno) DESC LIMIT 1; END; It works, I just tried it in postgresql, the last idno is visible to the user making the transaction, and will be unavailable to others. From php-general-return-116731-bob_parker=dodo.com.au@lists.php.net Wed Sep 18 22:34:13 2002 Envelope-to: bob@localhost Mailing-List: contact php-general-help@lists.php.net; run by ezmlm Precedence: bulk list-help: <mailto:php-general-help@lists.php.net> list-unsubscribe: <mailto:php-general-unsubscribe@lists.php.net> list-post: <mailto:php-general@lists.php.net> Delivered-To: mailing list php-general@lists.php.net From: Jon Haworth <jhaworth@witanjardine.co.uk> To: 'bob parker' <bob_parker@dodo.com.au>, php-general@lists.php.net Date: Wed, 18 Sep 2002 13:27:56 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" Subject: RE: [PHP] Auto-increment value X-UIDL: *ab"!\-5!!-$7!!nk~!! Hi Bob, > SELECT idno ORDER BY idno DESC LIMIT 1; > assuming idno is what gets auto incremented That's not the best idea - what happens if two users are inserting records into the table at nearly-but-not-quite the same time? 1. Insert A goes through 2. Insert B goes through 3. LastID A returns the ID of B 4. LastID B returns the ID of B Whoever did insert A would receive the wrong ID. Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php bob

« previous php.general (#116733) next »