Re: MySQL INSERT

From: Date: Mon, 19 Nov 2001 04:31:45 +0000
Subject: Re: MySQL INSERT
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75066@lists.php.net to get a copy of this message
On Mon, 19 Nov 2001 14:51, Justin French wrote: > Hi, > > I'm inserting into a table (as I've done millions of times), and I have > a column called "id", which is an auto incrementing, unique field. > > Since it's auto-increment field, I have no idea what it is at the time > of insert, but I want to be able to report it to the screen. > > "Thankyour for your application, for future reference, your application > # is "<the id number of the application i just inserted>." > > > So, what I'd like to do is INSERT, then find out the id of the row I > just inserted. > > > I can't just look up the most recent id, because it's *possible* that > someone else could have inserted after me. > > Also, at this stage the id field is the only unique field, so I can't > try and match against annother field (of which I know the value I > inserted). > > > Any ideas? > > > Justin French mysql_insert_id is your friend, in this case. Even if someone inserts another record, this function will return the auto ID for the last insert performed using a given link identifier. So you feed it the link identifier for _your_ insert, which of course you know, and Bob's yer uncle :-) -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Vultures only fly with carrion luggage.

« previous php.general (#75066) next »