[php] how can I use pdo to get the last inserted data?

user structure

< table > < thead > < tr > < th > id < / th > < th > user < / th > < th > pwd < / th > < th > create_time < / th > < th > update_time < / th > < / tr > < / thead > < / table >
$pdo = new PDO(...);// pdo 
$stmt = $pdo->prepare("insert `user` (`user`,`pwd`) values("aaa","bbb")");

$res = $stmt->execute(); // (bool)true
$stmt->rowCount(); // 1   
$pdo->lastInsertId(); // 1 ID
// 

if the insert is successful, you get

< table > < thead > < tr > < th > id < / th > < th > user < / th > < th > pwd < / th > < th > create_time < / th > < th > update_time < / th > < / tr > < / thead > < tbody > < tr > < td > 1 < / td > < td > aaa < / td > < td > bbb < / td > < td > 100000000 < / td > < td > 100000000 < / td > < / tr > < / tbody > < / table >

for example, the front end wants to get a newly created json object {"id": 1, "user": "aaa", "pwd": "bbb", "create_time": "100000000", "update_time": "100000000"}
how to return this data?

Mar.24,2021

you can query the records through lastInsertId,. Any return

Menu