开发者

Equivalent of mysql_insert_id() for Postgresql? [duplicate]

开发者 https://www.devze.com 2023-01-02 10:22 出处:网络
This question already has answers here: 开发者_JAVA百科Closed 12 years ago. Possible Duplicate: mysql_insert_id alternative for postgresql
This question already has answers here: 开发者_JAVA百科 Closed 12 years ago.

Possible Duplicate:

mysql_insert_id alternative for postgresql

Is there a Postgresql equivalent of mysql_insert_id() to get the ID generated in the last query ??


If you are using PostgreSQL 8.2 or newer then the simplest way is to use RETURNING:

$result = pg_query($db, "INSERT INTO foo (bar) VALUES (123) RETURNING foo_id");
$insert_row = pg_fetch_row($result);
$insert_id = $insert_row[0];

For other alternatives see this duplicate.

0

精彩评论

暂无评论...
验证码 换一张
取 消