Reputation: 7391
I have a query:
pg_query("
INSERT INTO all_types (type) VALUES('something1')
RETURNING id;
");
How can I receive the answer from postgres whatever it is? In this case, I want to receive last id. Once I perform this query in Adminer, I get the answer with id, but I don't know how to get in in PHP code.
Upvotes: 0
Views: 320
Reputation: 418
Try to pg_fetch_result
. It will be something like:
$resource = pg_query($connection, "INSERT INTO all_types (type) VALUES('something1') RETURNING id;");
$result = pg_fetch_result($resource);
Additionally pg_query
takes 2 parameters: first is connection to your db, which isn't present in your example.
Upvotes: 2