Newbie MySQL Question

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
e3
Forum Newbie
Posts: 2
Joined: Wed Jun 19, 2002 1:29 am

Newbie MySQL Question

Post by e3 »

I have a table with a standard auto numbered primary key, I was wondering if there's any way for MySQL to return the id number of the record it inserts after inserting it (if that made any sense) without running another query.

Thanks for your time.
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 mysql_insert_id() (it has to be run directly after the query):

Code: Select all

mysql_query("INSERT .... ");
$id = mysql_insert_id();
or LAST_INSERT_ID().

Mac
e3
Forum Newbie
Posts: 2
Joined: Wed Jun 19, 2002 1:29 am

Post by e3 »

Excellent :o

Thanks so much!
Post Reply