downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/pdo.lastinsertid.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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',
  ),
 
'up' =>
  array (
   
0 => 'class.pdo.php',
   
1 => 'The PDO class',
  ),
 
'prev' =>
  array (
   
0 => 'pdo.getavailabledrivers.php',
   
1 => 'PDO::getAvailableDrivers',
  ),
 
'next' =>
  array (
   
0 => 'pdo.prepare.php',
   
1 => 'PDO::prepare',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="pdo.lastinsertid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::lastInsertId</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, 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>
 <a name="pdo.lastinsertid.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>PDO::lastInsertId</b></span>
    ([ <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt><span class="initializer"> = NULL</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,
   <b>PDO_PGSQL()</b> requires you to specify the name of
   a sequence object for the <i><tt class="parameter">name</tt></i>
 parameter.
  </p>
  <blockquote><p><b class="note">Note</b>:
  
    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.
   <br />
  </p></blockquote>
 </div>


 <a name="pdo.lastinsertid.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Name of the sequence object from which the ID should be returned.
      </p>
     </dd>

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


 <a name="pdo.lastinsertid.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   If a sequence name was not specified for the <i><tt class="parameter">name</tt></i>

   parameter, <b>PDO::lastInsertId()</b> 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 <i><tt class="parameter">name</tt></i>

   parameter, <b>PDO::lastInsertId()</b> 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,
   <b>PDO::lastInsertId()</b> triggers an
   <i>IM001</i> SQLSTATE.
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites