Re: Adding Records & Capture The New Record ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2009-02-07 at 15:26 -0500, tedd wrote:
> At 12:12 PM -0800 2/7/09, revDAVE wrote:
> >On 2/7/2009 11:41 AM, "Stuart" <stuttle@xxxxxxxxx> wrote:
> >
> >>>  Then, after I inserted the record -  I would do a quick query that would
> >>>  retrieve the record ID by searching for the random number
> >>
> >>  Ouch that's nasty!!
> >>
> >>>  Q: is there a better way to retrieve the record ID from the newly added
> >>>  record?
> >>
> >>  Use an auto_increment field then, assuming MySQL you can use
> >  > mysql_insert_id to get the ID of the last record inserted on a given
> >>  connection.
> >>
> >>  -Stuart
> >
> >Thanks Stuart - it works great - so much Less Nasty!
> >
> >BTW: as long as - mysql_insert_id is right after the insert statement - is
> >it 100% accurate - (in that no other insert from another user could get in
> >the middle of this)?
> 
> 
> That's one way, to use "mysql_insert_id" (probably the best).
> 
> But another is simply to read back in the record you just created and 
> check the $row['id']. That's the way I do it sometimes.
> 
> Cheers,
> 
> tedd
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 
How do you plan on reading back the row if you don't use the
mysql_insert_id value? For most cases, it's not enough to read back the
values you just put in as they may be the same for some people.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux