简体   繁体   中英

Get the last inserted system id of a certain table before doing any query pdo php

From this tutorial i found a way to get the last inserted id of a specific table (with pdo).In the example

$result = $db->exec("INSERT INTO table(firstname, lastname) VAULES('John', 'Doe')");
$insertId = $db->lastInsertId();

he made a query before getting the id i would to make something like this but i want to get the id oft he last inserted entry first before doing any query. How should i tell the code that it should check the last inserted id from this table . Any idea is appreciated.

Update

I want to get the last inserted id of a not only the last inserted id of the database 的不仅是数据库的最后插入的ID

Try this...

its return last inserted id before any query run.

select * from yourtable order by id desc limit 0,1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM