RE: Getting the value of an auto-increment

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

 



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:  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
>


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux