<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pgsql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.pg-last-oid.php',
    1 => 'pg_last_oid',
    2 => 'Liefert den Objektbezeichner (OID) des zuletzt eingef&uuml;gten Datensatzes',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL-Funktionen',
  ),
  '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' => 'de',
    '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);

?>
<div id="function.pg-last-oid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_last_oid</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_last_oid</span> &mdash; <span class="dc-title">Liefert den Objektbezeichner (OID) des zuletzt eingefügten Datensatzes</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-last-oid-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_last_oid</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-result.php" class="type PgSql\Result">PgSql\Result</a></span> <code class="parameter">$result</code></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_last_oid()</strong></span> wird benutzt, um den Object-Identifier
   <var class="varname">OID</var> des zuletzt eingefügten Datensatzes zu ermitteln.
  </p>
  <p class="para">
   Ab PostgreSQL 7.2 ist das Feld OID optional und ab der Version 8.1 wird es
   nicht mehr standardmäßig in den Tabellen enthalten sein. Falls eine Tabelle
   ohne OID definiert wurde, muss mit der Funktion
   <span class="function"><a href="function.pg-result-status.php" class="function">pg_result_status()</a></span> geprüft werden, ob ein Datensatz
   korrekt eingefügt wurde.
  </p>
  <p class="para">
   Um den Wert eines <code class="literal">SERIAL</code>-Feldes in einem gerade
   eingefügten Datensatz zu erhalten, ist der Aufruf der PostgreSQL-Funktion
   <code class="literal">CURRVAL</code> notwendig. Dem Aufruf muss der Name der in
   dieser Datenbanksitzung zuletzt benutzten Sequenz übergeben werden. Ist der
   Name dieser Sequenz unbekannt, muss er ab PostgreSQL 8.0 mittels der
   Funktion <code class="literal">pg_get_serial_sequence</code> ermittelt werden.
  </p>
  <p class="para">
   PostgreSQL enthält eine Funktion <code class="literal">LASTVAL</code>, die den Wert
   der zuletzt benutzten Sequenz der aktuellen Datenbanksitzung zurückgibt.
   Sie macht die Angabe von Sequenz, Tabelle und Spalte überflüssig.
  </p>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Diese Funktion ersetzt die Funktion <span class="function"><strong>pg_getlastoid()</strong></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-last-oid-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">result</code></dt>
     <dd>
      <p class="para">Eine <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>-Instanz, die von <span class="function"><a href="function.pg-query.php" class="function">pg_query()</a></span>,
<span class="function"><a href="function.pg-query-params.php" class="function">pg_query_params()</a></span> oder <span class="function"><a href="function.pg-execute.php" class="function">pg_execute()</a></span> (unter anderen) zurückgegeben wurde.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-last-oid-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Ein <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> oder <span class="type"><a href="language.types.string.php" class="type string">string</a></span> mit der OID des zuletzt eingefügten Datensatzes für
   die angegebene <code class="parameter">connection</code> oder <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, falls ein
   Fehler auftrat oder falls es keine OID gibt.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.pg-last-oid-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Beschreibung</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  Der Parameter <code class="parameter">result</code> erwartet nun eine <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>-Instanz;
  vorher wurde eine <a href="language.types.resource.php" class="link">Ressource</a> erwartet.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-last-oid-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>pg_last_oid()</strong></span>-Beispiel</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />  </span><span style="color: #FF8000">// Mit der Datenbank verbinden<br />  </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=mark host=localhost"</span><span style="color: #007700">);<br /><br />  </span><span style="color: #FF8000">// Beispieltabelle erzeugen<br />  </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test (a INTEGER) WITH OIDS"</span><span style="color: #007700">);<br /><br />  </span><span style="color: #FF8000">// Daten einfügen<br />  </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test VALUES (1)"</span><span style="color: #007700">);<br /><br />  </span><span style="color: #0000BB">$oid </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_last_oid</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-last-oid-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-query.php" class="function" rel="rdfs-seeAlso">pg_query()</a> - F&uuml;hrt eine Abfrage aus</span></li>
    <li><span class="function"><a href="function.pg-result-status.php" class="function" rel="rdfs-seeAlso">pg_result_status()</a> - Liefert den Status eines Abfrageergebnisses</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>