Get auto increment insert ID

From JumbaWiki

Jump to: navigation, search

Generally when finding an ID of an added item in MySQL you have to make two database calls and store ids which takes a lot of unnecessary server load. Here's a way to easily get the ID of an auto incremented field.

Start with your standard mysql insert query. See MySQL INSERT.

mysql_query("INSERT etc...");

This finds the id of the row once it has been added:

$id = mysql_insert_id();

That's it!

See also

Personal tools
Australian Photography | Unique Views of Reality | Daedalus