Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2532

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the auto generated ID of the last insert query that successfully 
  executed on this connection</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.db2-get-option.html">db2_get_option</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-lob-read.html">db2_lob_read</a></div>
 <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.db2-last-insert-id" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_last_insert_id</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.7.1)</p><p class="refpurpose"><span class="refname">db2_last_insert_id</span> &mdash; <span class="dc-title">Returns the auto generated ID of the last insert query that successfully 
  executed on this connection</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.db2-last-insert-id-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>db2_last_insert_id</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$resource</code></span>      
   )</div>

  <p class="para rdfs-comment">
   Returns the auto generated ID of the last insert query that successfully 
  executed on this connection.
  </p>
  <p class="para">
   The result of this function is not affected by any of the following:
   <ul class="itemizedlist">
    <li class="listitem">
     <p class="para">
      A single row INSERT statement with a VALUES clause for a table without an identity column.
     </p>
    </li>
    <li class="listitem">
     <p class="para">
      A multiple row INSERT statement with a VALUES clause.
     </p>
    </li>
    <li class="listitem">
     <p class="para">
      An INSERT statement with a fullselect.
     </p>
    </li>
    <li class="listitem">
     <p class="para">
      A ROLLBACK TO SAVEPOINT statement.
     </p>
    </li>
   </ul>
  </p>   
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.db2-last-insert-id-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">resource</code></em></span>
     <dd>

      <p class="para">
       A valid connection resource as returned from  <span class="function"><a href="function.db2-connect.html" class="function">db2_connect()</a></span> 
       or  <span class="function"><a href="function.db2-pconnect.html" class="function">db2_pconnect()</a></span>. The value of this parameter cannot be a 
       statement resource or result set resource.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.db2-last-insert-id-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the auto generated ID of last insert query that successfully 
  executed on this connection.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.db2-last-insert-id-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="db2-last-insert-id.example.basic">
    <p><strong>Example #1 A  <span class="function"><strong>db2_last_insert_id()</strong></span> example</strong></p>
    <div class="example-contents"><p>
      The following example shows how to return the  
      auto generated ID of last insert query that successfully 
      executed on this connection.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SAMPLE"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$user&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"db2inst1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"ibmdb2"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br />if(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$createTable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;lastInsertID&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(id&nbsp;integer&nbsp;GENERATED&nbsp;BY&nbsp;DEFAULT&nbsp;AS&nbsp;IDENTITY,&nbsp;name&nbsp;varchar(20))"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$insertTable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;lastInsertID&nbsp;(name)&nbsp;VALUES&nbsp;('Temp&nbsp;Name')"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;@</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$createTable</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Checking&nbsp;for&nbsp;single&nbsp;row&nbsp;inserted.&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$insertTable</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;&nbsp;</span><span style="color: #0000BB">db2_last_insert_id</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Last&nbsp;Insert&nbsp;ID&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"No&nbsp;Last&nbsp;insert&nbsp;ID.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />}<br />else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Connection&nbsp;failed."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Last Insert ID is : 1
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.db2-get-option.html">db2_get_option</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-lob-read.html">db2_lob_read</a></div>
 <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>