Reply to comment

How to get the last created auto-increment ID from a MySQL table

If you’re like me then you’re developing like crazy.  Once in a while you may need to retrieve the auto-increment ID value from the last created row you inserted into a particular mysql table.  Yea… when you insert a new row into a mysql table there is no apparent way to just return the ID from the row’s auto-increment field.  So to do this using PHP, simply use the

mysql_insert_id()

functin, which will return the last created ID as an interger.

The only catch is that you will want to run this function RIGHT after you do your insert, else some other process might create a new row after yours which would prevent you from obtaining the correct ID.

Anyways, short and sweet but saved a bunch of time on my end!

Reply

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
12 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.