<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.pg-last-oid.php',
    1 => 'pg_last_oid',
    2 => 'Retourne l\'identifiant de la derni&egrave;re ligne',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'pg_cancel_query',
  ),
  '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' => 'fr',
    '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">
   Retourne l&#039;identifiant de la dernière ligne
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-last-oid-description">
  <h3 class="title">Description</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> sert à récupérer le <var class="varname">OID</var>
   assigné à une ligne insérée.
  </p>
  <p class="para">
   Le champ OID est devenu optionnel depuis PostgreSQL 7.2 et ne sera plus
   présent par défaut dans PostgreSQL 8.1. Lorsque
   le champ OID n&#039;est pas présent dans la table, le programmeur doit utiliser
   <span class="function"><a href="function.pg-result-status.php" class="function">pg_result_status()</a></span> pour vérifier si la ligne
   a été correctement insérée.
  </p>
  <p class="para">
   Pour obtenir la valeur d&#039;un champ <code class="literal">SERIAL</code> dans une ligne
   insérée, il est nécessaire d&#039;utiliser la fonction
   <code class="literal">CURRVAL</code> de PostgreSQL en nommant la séquence à qui la
   dernière valeur est requise. Si le nom de la séquence est inconnu, la
   fonction PostgreSQL 8.0 <code class="literal">pg_get_serial_sequence</code> est
   nécessaire.
  </p>
  <p class="para">
   PostgreSQL 8.1 a une fonction <code class="literal">LASTVAL</code> qui retourne la valeur
   de la séquence la plus récemment utilisée de la session. Ceci permet d&#039;éviter
   de nommer la séquence, la table ou la colonne.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Auparavant, cette fonction s&#039;appelait <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">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">result</code></dt>
     <dd>
      <p class="para">
 Une instance <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>, retourné par <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>, ou <span class="function"><a href="function.pg-execute.php" class="function">pg_execute()</a></span> (entre autres).
</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-last-oid-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Un <a href="language.types.integer.php" class="link">entier</a> ou <a href="language.types.string.php" class="link">chaîne de caractères</a> contenant le OID assigné à la plus récente ligne insérée dans
   la connexion <code class="parameter">connection</code> spécifiée ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en cas
   d&#039;erreur ou de OID indisponible.
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  Le paramètre <code class="parameter">result</code> attend désormais une instance de
  <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span> ; auparavant, une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> était attendu.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-last-oid-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>pg_last_oid()</strong></span></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">// Connect to the database<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">// Create a sample table<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">// Insert some data into it<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">Voir aussi</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> - Ex&eacute;cute une requ&ecirc;te PostgreSQL</span></li>
    <li><span class="function"><a href="function.pg-result-status.php" class="function" rel="rdfs-seeAlso">pg_result_status()</a> - Lit le statut du r&eacute;sultat</span></li>
   </ul>
  </p>
 </div>

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