<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.pg-last-oid.php',
    1 => 'pg_last_oid',
    2 => '返回上一条记录的 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' => 'zh',
    '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">返回上一条记录的 oid</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-last-oid-description">
  <h3 class="title">说明</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> 用于检索分配给插入行的 <var class="varname">OID</var>。
  </p>
  <p class="para">
   从 PostgreSQL 7.2 开始 OID 字段成为可选项，在 PostgreSQL 8.1 中默认不存在。如果表中没有定义 OID 字段，程序员必须用
   <span class="function"><a href="function.pg-result-status.php" class="function">pg_result_status()</a></span> 检查记录是否成功插入。
  </p>
  <p class="para">
   要在插入的行中获取 <code class="literal">SERIAL</code> 字段的值，必须使用 PostgreSQL <code class="literal">CURRVAL</code>
   函数，命名需要最后一个值的序列。如果序列名称未知，则需要 <code class="literal">pg_get_serial_sequence</code> PostgreSQL 8.0 函数。
  </p>
  <p class="para">
   PostgreSQL 8.1 有一个函数 <code class="literal">LASTVAL</code>，它返回会话中最近使用的序列的值。这避免了对序列、表或列的命名需求。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    本函数以前的名字为 <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">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">result</code></dt>
     <dd>
      <p class="para"><span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span> 实例，由
<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> 或者 <span class="function"><a href="function.pg-execute.php" class="function">pg_execute()</a></span>（等）返回。</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-last-oid-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 或 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>，包含分配给指定 <code class="parameter">connection</code> 中最近插入的行的 OID，如果出错或没有可用的 OID，则为 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-last-oid-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">result</code> 参数接受 <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>
  实例，之前接受 <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-last-oid-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <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">// 连接到数据库<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">// 创建示例表<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">// 插入一些数据<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">参见</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> - 执行查询</span></li>
    <li><span class="function"><a href="function.pg-result-status.php" class="function" rel="rdfs-seeAlso">pg_result_status()</a> - 获得查询结果的状态</span></li>
   </ul>
  </p>
 </div>

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