开发者

Equivalent of mysql_insert_id() for Postgresql? [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜