Re: last inserted record
| From: | Christian Reiniger | Date: | Thu, 08 Mar 2001 09:40:57 +0000 |
| Subject: | Re: last inserted record | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43014@lists.php.net to get a copy of this message | ||
On Thursday 08 March 2001 10:31, you wrote:
> > On Thursday 08 March 2001 06:42, you wrote:
> > > Assuming that you do have a primary key, how can you grab the last
> > > record you inserted? Can you use @@IDENTITY, or something like
> > > that?
> >
> > For that I'd add another field - type "timestamp".
> > In MySQL, timestamp fields are automatically set to NOW() on each
> > insert and update *if* they are not set to something else in it (the
> > insert or update)
>
> I would prefer using mysql_insert_id() if possible.
> http://www.php.net/manual/en/function.mysql-insert-id.php
Which however only works (1) with autoincrement keys and (2) for the last
insert you did using the same mysql connection, i.e. if you do an insert
in foo.php, mysql_insert_id () won't show anything in bar.php
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
Very funny, Scotty! Now beam up my clothes...