I am using Postgresql, when I want to use PDO to retrieve the latest insertion ID, I got a problem. Here is my code:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "columnName" does not exist
Returns the ID of the last inserted row, or the last value from a sequence object,
depending on the underlying driver. For example, PDO_PGSQL() requires you to specify the
name of a sequence object for the name parameter.
PostgreSQL uses sequences to generate values for
serial columns and
serial columns are generally what is used for "auto-incrementing" columns in PostgreSQL. Sequences have names and are, in general, independent of any particular table so you could have one sequence generating unique IDs for several different tables; the sequence name is what
lastInsertId wants as its argument:
For example, PDO_PGSQL() requires you to specify the name of a sequence object for the name parameter.
The sequence object created by PostgreSQL is automatically named
$id = $db->lastInsertId('tableName_columnName_seq');