PHP gets insert ID with PDO This method may have concurrency problems

Source: Internet
Author: User
Call the Prepare method to prepare the query
$stmt = $pdo->prepare ($sql);

Pass an array to the named parameter binding value in the preprocessing query, and execute the SQL
$stmt->execute (Array (': Name ' = ' Harry '));

Gets the ID value of the last inserted data
echo $pdo->lastinsertid (). '
';

This approach may have concurrency problems.

Reply content:

Call the Prepare method to prepare the query
$stmt = $pdo->prepare ($sql);

Pass an array to the named parameter binding value in the preprocessing query, and execute the SQL
$stmt->execute (Array (': Name ' = ' Harry '));

Gets the ID value of the last inserted data
echo $pdo->lastinsertid (). '
';

This approach may have concurrency problems.

Every link in MySQL is a session
The $pdo->lastInsertId() last insertion ID of the current session is obtained

This $pdo is private and does not take the data that someone else has inserted.
The code is executed from the top down one line, even if you write a loop.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.