Home > Backend Development > PHP Tutorial > PHP uses pdo to obtain insert id. This method may have concurrency issues.

PHP uses pdo to obtain insert id. This method may have concurrency issues.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-09-08 08:44:01
Original
1768 people have browsed it

//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

Reply content:

//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.

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template