Returning An Auto_Increment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nonny
Forum Newbie
Posts: 2
Joined: Fri Nov 15, 2002 9:46 am

Returning An Auto_Increment

Post by nonny »

When sending a INSERT query to insert a row into a mySQL table, i wish to have it return the auto_increment assigned to the ID field of the new record.
I could use a seperate query and use the LAST_INSERT_ID () to return the ID of the last field, but is there a quicker way?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can use PHP's mysql_insert_id() function immediately after the INSERT in order to get the ID.

Mac
Post Reply