MySQL PDO Connection,如何检索插入的ID? [重复]

This question already has an answer here:

I have a PDO connection where I am inserting a new ROW in the databse:

$sql = UPDATE invoices SET ..."

Or

$sql = INSERT INTO invoices ..."

Then:

$stmt = self::getPDOConnection(self::DEFAULT_CONNECTION_NAME)->prepare($this->sql);
$stmt->execute($this->values);

And I would like to get the id of the updated, inserted element.

Thank you.

</div>

You can use this.

public string PDO::lastInsertId ([ string $name = NULL ] )

FYI Link