Page 1 of 1

geting last inserted row Id (MySQL)

Posted: Sat Jun 03, 2006 2:47 pm
by alexus
Hi
If I have INSERT command and I have id column in my table (autoincrement, primary key)
When I di inser i want to find out what is the ID, that db assidned for the row. .

what command should i use?

Thanks!

Posted: Sat Jun 03, 2006 2:52 pm
by Burrito
take a look at mysql_insert_id()

Posted: Sat Jun 03, 2006 3:05 pm
by alexus
just what i need, THANKS~

Posted: Thu Jun 08, 2006 4:48 pm
by Li0rE
before I knew how to use insertid function (which was before I read your post) I just inserted all the information and queried

Code: Select all

$query = mysql_query("SELECT id FROM table WHERE something = '$somethingthatwasinsertedrightbeforethis'");
$row = mysql_fetch_assoc($query);
$id = $row['id'];

Posted: Thu Jun 08, 2006 4:51 pm
by alexus
Li0rE, I was talking about INSERT not SELECT