I’m using PDO with PostgreSQL in PHP.
I’ll let my users uploads files.
I would like to add the record id to the saved image.
Is it possible to get (or reserve) the record id before insertion in the database.
I don’t think this is possible just want to be sure.
Yes it is, you should use postgres function
nextvalto fetch the next value in the sequence. Look the default value in your table’s id column, it should contain a nextval call to the used sequence.For example if the table looks something like this:
You can call:
which will “reserve” the id for you to be used later on: