I have a mysql table where the id column is set to AUTOINCREMENT and a PRIMARY KEY is associated with it. If my table has some records in it already then to get the last id I query like this
$sql = $db->prepare("SELECT `id` FROM `table` ORDER BY `id` DESC LIMIT 1");
$sql->execute();
Now considering my last record id is say about 224, then all the rows get deleted due to some function maybe. Then I want the last id for another querying purpose in which I want to add 1 with it.
$tobeinserted = $lastid + 1;
But since all the rows get deleted, I cannot query like the previous one. So how do I get it?