mysql_insert_id alternative for postgresql

后端 未结 4 532
借酒劲吻你
借酒劲吻你 2020-12-01 15:53

is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks are solving the problem partially by finding the current value

4条回答
  •  广开言路
    2020-12-01 16:50

    You also can use:

    $result = pg_query($db, "INSERT INTO foo (bar) VALUES (123) RETURNING foo_id");
    $insert_row = pg_fetch_result($result, 0, 'foo_id');
    

    You have to specify in pg_fetch_result the number of the row and the name of the field that you are looking for, this is a more precise way to get the data that you need, but I don't know if this has some penalty in the performance of the query. Remember that this method is for PostgreSQL versions 8.2 and up.

提交回复
热议问题