0
I am using php and postgres on a web system, I have a form that I am saving by using the Insert using pg_query, however, I would like to get the id of the new record after inserting, but I am not succeeding, or returns null or false. What I’ve already tried:
$resultado = pg_query($sql);
var_dump(pg_last_oid(pg_affected_rows($resultado)));
$resultado = pg_query($sql);
var_dump(pg_last_oid($resultado));
$row = pg_fetch_row($resultado);
var_dump($row[0]);
$row = pg_fetch_array($resultado, null, PGSQL_ASSOC);
var_dump($row[0]);
Nothing worked out, there’s a way to do it ?
where the command is?
– user41630
have to see how postgresql works with the parameters in php, but the query would be something like this:
insert into tabela (id,nome) values (1,'Teste') returning id;
– Rovann Linhalis
var_dump(pg_last_oid($resultado));
– Valdeir Psr
If id is a quence can do thus with the returning.
– rray