How to get the id of a just written row?

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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

How to get the id of a just written row?

Post 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?
peDey
Forum Newbie
Posts: 1
Joined: Sat Aug 02, 2003 9:57 pm

Post by peDey »

Have you looked at mysql_insert_id ?
http://au2.php.net/manual/en/function.m ... ert-id.php
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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!
Post Reply