<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'pdo.lastinsertid.php',
    1 => 'PDO::lastInsertId',
    2 => 'Returns the ID of the last inserted row or sequence value',
  ),
  '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' => 'en',
    '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">
   Returns the ID of the last inserted row or sequence value
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.lastinsertid-description">
  <h3 class="title">Description</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">
   Returns the ID of the last inserted row, or the last value from a
   sequence object, depending on the underlying driver. For example,
   <a href="ref.pdo-pgsql.php" class="link">PDO_PGSQL</a> allows the name of any
   sequence object to be specified for the <code class="parameter">name</code> parameter.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This method may not return a meaningful or consistent result across
    different PDO drivers, because the underlying database may not even
    support the notion of auto-increment fields or sequences.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.lastinsertid-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       Name of the sequence object from which the ID should be returned.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.lastinsertid-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   If a sequence name was not specified for the <code class="parameter">name</code>
   parameter, <span class="methodname"><strong>PDO::lastInsertId()</strong></span> returns a
   string representing the row ID of the last row that was inserted into
   the database.
  </p>
  <p class="para">
   If a sequence name was specified for the <code class="parameter">name</code>
   parameter, <span class="methodname"><strong>PDO::lastInsertId()</strong></span> returns a
   string representing the last value retrieved from the specified sequence
   object.
  </p>
  <p class="para">
   If the PDO driver does not support this capability,
   <span class="methodname"><strong>PDO::lastInsertId()</strong></span> triggers an
   <code class="literal">IM001</code> SQLSTATE.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo.lastinsertid-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
Emits an error with level <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> is set
to <strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong>.
</p>
<p class="para">
Throws a <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong>
is set to <strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong>.
</p>
 </div>


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