如何使用php中的PDO transactionno在插入后获得插入ID


How to get the insert ID after insert using the PDO transactino in php

在制作commit之前,如何在PHP 中使用事务插入后获得row ID

$qry = $con->prepare("/* query */");
$con->beginTransaction();
$qry->execute();
    $last_id = $con->lastInsertId();    // This
$con->commit();

请求您的pdo对象给出插入的最后一个id:

$lastId = $pdoObject->lastInsertId();