Rechercher une fonction PHP

pg_last_oid

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

pg_last_oidReturns the last row's OID

Description

pg_last_oid ( resource $result ) : string

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.

Note:

This function used to be called pg_getlastoid().

PHP: pg_last_oid - Manual Home of Manuel PHP  Contents Haut

Parameters

result

PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).

PHP: pg_last_oid - Manual Home of Manuel PHP  Contents Haut

Return Values

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

PHP: pg_last_oid - Manual Home of Manuel PHP  Contents Haut

Examples

Example #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);
?>

PHP: pg_last_oid - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.pg-last-oid.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut