[PHPwestoz] getting the last inserted id in mysql

Samuel Cochran sj26 at sj26.com
Tue Feb 22 23:01:02 UTC 2005


Mike Fewings wrote:

>> Unfortunately I don't know any function in MySQL that lets you 
>> retrieve the auto-increment ID of a field you just created. You 
>> normally have to do another select, which is not hard if you do this: 
>> "SELECT ID FROM Artists ORDER BY ID DESC LIMIT 1" This will give you 
>> the last created ID, which normally would be the last record you 
>> created.
>
> This function can retreive the last insert id from the database
>
>                select last_insert_id() as feild_id
>
> and make this query immediately after the insert and it will return 
> the last id that was inserted by auto increment.

Alternatively, one can use the mysql_next_id() function of PHP. Have a 
look: http://php.net/mysql-next-id

-- Samuel Cochran
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3154 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.linux.org.au/pipermail/phpwestoz/attachments/20050222/d42242ac/attachment.bin 


More information about the PHPwestoz mailing list