Page 1 of 1

Newbie MySQL Question

Posted: Wed Jun 19, 2002 1:29 am
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.

Posted: Wed Jun 19, 2002 1:43 am
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

Posted: Wed Jun 19, 2002 1:47 am
by e3
Excellent :o

Thanks so much!