★ wanayoo — archive 1999 http://php.net/manual/hu/function.pg-getlastoid.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PostgreSQL
Quick Reference
PostgreSQL
English version of this pageGerman version of this pageJapanese version of this page
Italian version of this pageFrench version of this pageHungarian version of this page
Spanish version of this page
* pg_close
* pg_cmdtuples
* pg_connect
* pg_dbname
* pg_errormessage
* pg_exec
* pg_fetch_array
* pg_fetch_object
* pg_fetch_row
* pg_fieldisnull
* pg_fieldname
* pg_fieldnum
* pg_fieldprtlen
* pg_fieldsize
* pg_fieldtype
* pg_freeresult
* pg_getlastoid
* pg_host
* pg_loclose
* pg_locreate
* pg_loexport
* pg_loimport
* pg_loopen
* pg_loread
* pg_loreadall
* pg_lounlink
* pg_lowrite
* pg_numfields
* pg_numrows
* pg_options
* pg_pconnect
* pg_port
* pg_result
* pg_trace
* pg_tty
* pg_untrace

  Thanks to:
 Chek.com
 easyDNS
 VA Linux Systems

  Related sites:
Apache
MySQL
PostgreSQL
Zend Tech.

  Community:
LinuxFund.org
OSDN
Manual: pg_getlastoid
View the source code for this pageSearch the site



Previous page
 pg_freeresult
 Updated
Mon, 21 Aug 2000
pg_host 
Next page


pg_getlastoid

(PHP3 , PHP4 )

pg_getlastoid -- Returns the last object identifier

Description

int pg_getlastoid (int result_id)

Pg_getlastoid() can be used to retrieve the oid assigned to an inserted tuple if the result identifier is used from the last command sent via pg_exec() and was an SQL INSERT. This function will return a positive integer if there was a valid oid. It will return -1 if an error occured or the last command sent via pg_exec() was not an INSERT.


User Contributed Notes: pg_getlastoid


jf_doyon@hotmail.com
30-Aug-2000 10:37
This is great for tables that use sequences to create a unique record ID ...

It turns out all PostgreSQL tables have a hidden column "oid" that holds a unique identifier. This function allows you to find out what OID was assigned to the last record you INSERTed, allowing to fetch the last record you inserted by using it's OID (I'm doing this to find out what value was assigned to a column from a sequence for instance).

Of course now that I know this, maybe I could've used the OID's from the bennning, avoiding the seuqences all together ! Ah well, lesson learned :)

J.F.



joarmc@swbell.net
23-Sep-2000 04:36
In response to the previous note.
Using a OID as a unique identifier is not generally wise. Unless you are very careful, you might end up with a tuple having a different OID if a database must be reloaded.

John McKown



 About Notes


Previous page
 pg_freeresult
 Updated
Mon, 21 Aug 2000
pg_host 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.