How do I get the last inserted ID of a MySQL table in PHP?

Viewed 414101

I have a table into which new data is frequently inserted. I need to get the very last ID of the table. How can I do this?

Is it similar to SELECT MAX(id) FROM table?

16 Answers

I tried

mysqli_insert_id($dbConnectionObj)

This returns the current connection's last inserted id, so if you are managing your connections properly this should work. Worked for me at least.

Related