I'm inserting records, primary key is a uniqueId created by PHP.
How to retrieve last inserted uniqueId from MySQL?
Tnx
See Question&Answers more detail:osI'm inserting records, primary key is a uniqueId created by PHP.
How to retrieve last inserted uniqueId from MySQL?
Tnx
See Question&Answers more detail:osIf it is an auto_incremented value you would use mysql_insert_id()
(or its mysqli sibling) immediately after doing an insert to get the ID assigned to it.
If you wanted to get a non-auto incremented value you would need to SELECT the row with the highest value and sort by that value in descending order to do the job (assuming it is numeric or alphanumeric and increments sequentially):
SELECT id FROM tablename ORDER id DESC LIMIT 1
If it is a random ID than you would need to sort by date:
SELECT id FROM tablename ORDER datecol DESC LIMIT 1
If you don't have any other method of sorting these records you can get the last row in the table but there is no guarantee that record is the newest and thus you have no accuracy in your results.