RE: [PHP-DB] Getting the value of an auto-increment
| From: | Jennifer Goodie | Date: | Fri, 11 Apr 2003 00:02:53 +0000 |
| Subject: | RE: [PHP-DB] Getting the value of an auto-increment | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26997@lists.php.net to get a copy of this message | ||
It depends on the type of database you are using. You could use last insert
id if you are using mysql mysql_insert_id()
http://www.php.net/manual/en/function.mysql-insert-id.php
Since you did not say what kind of database server you are using, it is hard
to give you a good answer.
> -----Original Message-----
> From: timbo@komrades.dyndns.org [mailto:timbo@komrades.dyndns.org]
> Sent: Thursday, April 10, 2003 4:59 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Getting the value of an auto-increment
>
>
> Hello,
>
> I'm using an auto-increment field in a table as the primary key. What I
> want to know is when I use an INSERT query to add a row to the table is
> there a way I can get the value of the auto-increment field of the row
> that was just inserted?
>
> What I'm currently doing is messy but works:
> I get the current time and session id and write them to one of the fields
> in the row and INSERT that. I then do a query and find the row (thus
> getting the value of the auto-increment field) and then write the real
> data.
>
> I'm just hoping there's an easier way.
>
> Thanks in advance,
>
> Tim Coombes
> Komrades Ink.
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>