<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.cubrid.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.cubrid-insert-id.php',
    1 => 'cubrid_insert_id',
    2 => 'Return the ID generated for the last updated AUTO_INCREMENT column',
  ),
  'up' => 
  array (
    0 => 'ref.cubrid.php',
    1 => 'CUBRID Functions',
  ),
  'prev' => 
  array (
    0 => 'function.cubrid-get-server-info.php',
    1 => 'cubrid_get_server_info',
  ),
  'next' => 
  array (
    0 => 'function.cubrid-is-instance.php',
    1 => 'cubrid_is_instance',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/cubrid/functions/cubrid-insert-id.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.cubrid-insert-id" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_insert_id</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_insert_id</span> &mdash; <span class="dc-title">Return the ID generated for the last updated <strong><code>AUTO_INCREMENT</code></strong> column</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-insert-id-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_insert_id</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$conn_identifier</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   The <span class="function"><strong>cubrid_insert_id()</strong></span> function retrieves the ID
   generated for the AUTO_INCREMENT column which is updated by the previous
   INSERT query. It returns 0 if the previous query does not generate new
   rows, or FALSE on failure.
  </p>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    CUBRID supports AUTO_INCREMENT for more than one columns in a table. In
    most cases, there will be a single AUTO_INCREMENT column in a table. If
    there are multiple AUTO_INCREMENT columns, this function should not be
    used even if it will return a value.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-insert-id-parameters">
 <h3 class="title">Parameters</h3>
 <dl>
  
   <dt><code class="parameter">conn_identifier</code></dt>
   <dd><span class="simpara">
     The connection identifier previously obtained by a call to
     <span class="function"><a href="function.cubrid-connect.php" class="function">cubrid_connect()</a></span>.
   </span></dd>
  
 </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-insert-id-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   A string representing the ID generated for an AUTO_INCREMENT column by the
   previous query, on success.
  </p>
  <p class="simpara">
   0, if the previous query does not generate new rows.
  </p>
  <p class="simpara">
    <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.cubrid-insert-id-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.4.0</td>
      <td>
       Change the return value from an array to string; Remove the first
       parameter class_name.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-insert-id-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>cubrid_insert_id()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #0000BB">33000</span><span style="color: #007700">, </span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br />@</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"DROP TABLE cubrid_test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"CREATE TABLE cubrid_test (d int AUTO_INCREMENT(1, 2), t varchar)"</span><span style="color: #007700">);<br /><br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt; </span><span style="color: #0000BB">10</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br />    </span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"INSERT INTO cubrid_test(t) VALUES('cubrid_test')"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$id </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_insert_id</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<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="examplescode"><pre class="examplescode">string(2) &quot;19&quot;</pre>
</div>
    </div>
  </div>
 </div>


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