<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'pdo.lastinsertid.php',
    1 => 'PDO::lastInsertId',
    2 => '最後に挿入された行の ID あるいはシーケンスの値を返す',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'pdo.intransaction.php',
    1 => 'PDO::inTransaction',
  ),
  'next' => 
  array (
    0 => 'pdo.prepare.php',
    1 => 'PDO::prepare',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/pdo/pdo/lastinsertid.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.lastinsertid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::lastInsertId</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDO::lastInsertId</span> &mdash; <span class="dc-title">
   最後に挿入された行の ID あるいはシーケンスの値を返す
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.lastinsertid-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::lastInsertId</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$name</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></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.singleton.php" class="type false">false</a></span></span></div>


  <p class="para rdfs-comment">
   最後に挿入された行の ID、
   あるいはシーケンスオブジェクトから次の値を返します。
   これは、構成しているドライバに依存します。例えば
   <a href="ref.pdo-pgsql.php" class="link">PDO_PGSQL</a> の場合、<code class="parameter">name</code>
   パラメータにシーケンスオブジェクト名を指定することができます。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    このメソッドは、異なる PDO ドライバ間で意味のあるもしくは
    一貫性のある結果を返さないかも知れません。
    構成しているデータベースが自動インクリメントフィールド、
    もしくはシーケンスの概念をサポートしていないかも知れないためです。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.lastinsertid-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       ID が返されるべきシーケンスオブジェクト名を指定します。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.lastinsertid-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   もし <code class="parameter">name</code>
   パラメータにシーケンス名が指定されなかった場合、
   <span class="methodname"><strong>PDO::lastInsertId()</strong></span>
   はデータベースに挿入された最後の行の行IDに相当する文字列を返します。
  </p>
  <p class="para">
   もし <code class="parameter">name</code>
   パラメータにシーケンス名が指定された場合、
   <span class="methodname"><strong>PDO::lastInsertId()</strong></span>
   は指定されたシーケンスオブジェクトから取得した最後の値に相当する
   文字列を返します。
  </p>
  <p class="para">
   もし PDO ドライバがサポートしていない場合、
   <span class="methodname"><strong>PDO::lastInsertId()</strong></span>
   は <code class="literal">IM001</code> SQLSTATE を発生させます。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo.lastinsertid-errors">
  <h3 class="title">エラー / 例外</h3>
  <p class="para">
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> が <strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong> に設定されていた場合、<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> レベルのエラーが発生します。
</p>
<p class="para">
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> が <strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong> に設定されていた場合、<span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> がスローされます。
</p>
 </div>


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