//Call the prepare method to prepare the query
$stmt = $pdo->prepare($sql);
//Pass an array to bind values to the named parameters in the preprocessing query and execute SQL
$stmt->execute(array(':name' => '王五'));
//Get the ID value of the last inserted data
echo $pdo->lastInsertId() . '
';
This method may have concurrency issues
//Call the prepare method to prepare the query
$stmt = $pdo->prepare($sql);
//Pass an array to bind values to the named parameters in the preprocessing query and execute SQL
$stmt->execute(array(':name' => '王五'));
//Get the ID value of the last inserted data
echo $pdo->lastInsertId() . '
';
This method may have concurrency issues
Every link in mysql is a session
and $pdo->lastInsertId()
is to get the last insert id of the current session
This $pdo is private to you and will not access data inserted by others.
The code is executed line by line from top to bottom, even if you write a loop, there will be nothing wrong.