Page 1 of 1

How to get the id of a just written row?

Posted: Sat Aug 02, 2003 8:54 pm
by patrikG
MySQL-database, field "id" is auto_increment. I am writing a record to the db and want to get the id.
I know I can do it with two mySQL-statements, one writing the record, the other reading the id, but is there something to obtain the id-field without querying again?

Posted: Sat Aug 02, 2003 9:57 pm
by peDey
Have you looked at mysql_insert_id ?
http://au2.php.net/manual/en/function.m ... ert-id.php

Posted: Sun Aug 03, 2003 3:04 am
by patrikG
Heh, it's been some time since I've been told to RTFM. ;)

Thanks, PeDey, that's exactly what I was looking for!