For the method PDO::lastInsertId(), what do they mean by the argument "sequence name"? (PHP - PDO)
Asked Answered
A

1

7

I am trying to use PDO's lastInsertId method, but the documentation states that for some rdbms I need a sequence name as an argument. Only being familiar with mysql, I am not quite sure what a sequence name is. Do they mean the name of the column that contains the auto-increment id? Here is the documentation for the method:

http://php.net/manual/en/pdo.lastinsertid.php

Any information on this would be greatly appreciated. Thanks.

Aubigny answered 28/4, 2011 at 18:35 Comment(0)
K
4

Instead of having a primary key auto_incrementing (i.e. MySQL), you can create a named sequence like this:

CREATE SEQUENCE a_sequence INCREMENT BY 5 START WITH 30

So you'd have a column with these values: 30, 35, 40... etc. The lastInsertId method should grab the last sequence value.

Kudva answered 28/4, 2011 at 18:46 Comment(3)
Gotcha, so the sequence and the column that the sequence is used on are two separate things. Thanks!Aubigny
When you use a "serial" data type, and various other primary keys in postgres, they get sequences created for them automatically as well.Berry
CREATE SEQUENCE in Mysql?Moitoso

© 2022 - 2024 — McMap. All rights reserved.