I need the last inserted record
in PHP without insert any data I need the id before insert
any data .
Asked
Active
Viewed 656 times
-1

Saty
- 22,443
- 7
- 33
- 51

Hoque MD Zahidul
- 10,560
- 2
- 37
- 40
-
select max(id) + 1 from your table, that will be the id you want. – Niranjan N Raju Sep 15 '15 at 09:50
-
Select Max(id) from table_name – Gautam Sep 15 '15 at 09:50
-
3`mysqli_insert_id($con)` – er.irfankhan11 Sep 15 '15 at 09:52
-
possible duplicate of [How do I get the last inserted ID of a MySQL table in PHP?](http://stackoverflow.com/questions/1685860/how-do-i-get-the-last-inserted-id-of-a-mysql-table-in-php) – Gunaseelan Sep 15 '15 at 09:58
-
@Hoque MD Zahidul i dont know why you need this but you most likly will run into race conditions with this. – Raymond Nijland Sep 15 '15 at 10:20
2 Answers
5
I hope this is what you're looking for
SELECT id FROM table ORDER BY id DESC LIMIT 1
Hope this helps you out

Amit Horakeri
- 747
- 5
- 18
1
Simply use
SELECT MAX(id) FROM your_table_name
Or using PDO
PDO::lastInsertId

Ankur Tiwari
- 2,762
- 2
- 23
- 40