Latest web development tutorials

PDO :: lastInsertId

PHP PDO Reference Manual PHP PDO Reference Manual

PDO :: lastInsertId - Returns the ID or sequence value for the last inserted row (PHP 5> = 5.1.0, PECL pdo> = 0.1.0)


Explanation

grammar

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

Returns the last inserted row ID, or the last value of a sequence object, depending on the bottom of the drive. For example, PDO_PGSQL () requires you to specify the sequence object for the name parameter name.

Note: between different PDO drivers, this method may not return a meaningful or consistent result, because the underlying database may not support the notion of auto-increment fields or sequences.


parameter

name
It should return the name ID of the sequence object.


return value

If you do not specify the sequence name as a parameter name, PDO :: lastInsertId () returns a string that represents the database row row ID of the last inserted.

If you specify a name for the sequence parameter name, PDO :: lastInsertId () returns a value from the retrieved last sequence specified string representation of the object.

If the current PDO driver does not support this feature, PDO :: lastInsertId () triggers an IM001 SQLSTATE.

PHP PDO Reference Manual PHP PDO Reference Manual