array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.pg-last-oid.php', 1 => 'pg_last_oid', 2 => 'Returns the last row\'s OID', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL Функції', ), 'prev' => array ( 0 => 'function.pg-last-notice.php', 1 => 'pg_last_notice', ), 'next' => array ( 0 => 'function.pg-lo-close.php', 1 => 'pg_lo_close', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/pgsql/functions/pg-last-oid.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

pg_last_oid

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_last_oidReturns the last row's OID

Опис

pg_last_oid(PgSql\Result $result): string|int|false

pg_last_oid() is used to retrieve the OID assigned to an inserted row.

OID field became an optional field from PostgreSQL 7.2 and will not be present by default in PostgreSQL 8.1. When the OID field is not present in a table, the programmer must use pg_result_status() to check for successful insertion.

To get the value of a SERIAL field in an inserted row, it is necessary to use the PostgreSQL CURRVAL function, naming the sequence whose last value is required. If the name of the sequence is unknown, the pg_get_serial_sequence PostgreSQL 8.0 function is necessary.

PostgreSQL 8.1 has a function LASTVAL that returns the value of the most recently used sequence in the session. This avoids the need for naming the sequence, table or column altogether.

Зауваження:

This function used to be called pg_getlastoid().

Параметри

result

Примірник PgSql\Result, якого повертає одна з функцій pg_query(), pg_query_params() або pg_execute() (серед інших).

Значення, що повертаються

An int or string containing the OID assigned to the most recently inserted row in the specified connection, or false on error or no available OID.

Журнал змін

Версія Опис
8.1.0 Тепер параметр result має бути примірником PgSql\Result. Раніше очікувався resource.

Приклади

Приклад #1 pg_last_oid() example

<?php
// Connect to the database
pg_connect("dbname=mark host=localhost");

// Create a sample table
pg_query("CREATE TABLE test (a INTEGER) WITH OIDS");

// Insert some data into it
$res = pg_query("INSERT INTO test VALUES (1)");

$oid = pg_last_oid($res);
?>

Прогляньте також