There is the various approach of selecting the last insert id from MySQL table.
- Select a single row from the table in descending order and store the id.
- Select Maximum value.
- The following query gives you next AUTO_INCREMENT value from selected table which you can use to get the last id.
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'user'
If your currently AUTO_INCREMENT column last value is 8 and when you execute the above query on the Table this will return 9.
In PHP there is an inbuilt method which simply returns the last insert id according to the previous insert query.