<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
  <refentry id="function.mysql-insert-id">
   <refnamediv>
    <refname>mysql_insert_id</refname>
    <refpurpose>
     Get the ID generated from the previous INSERT operation
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>int</type><methodname>mysql_insert_id</methodname>
      <methodparam choice="opt"><type>resource</type><parameter>
        link_identifier
       </parameter></methodparam>
     </methodsynopsis>
    <para>
     <function>mysql_insert_id</function> returns the ID generated for
     an AUTO_INCREMENT column by the previous INSERT query using the
     given <parameter>link_identifier</parameter>.  If
     <parameter>link_identifier</parameter> isn't specified, the last
     opened link is assumed.
    </para>
    <para>
     <function>mysql_insert_id</function> returns 0 if the previous
     query does not generate an AUTO_INCREMENT value. If you need to
     save the value for later, be sure to call
     <function>mysql_insert_id</function> immediately after the
     query that generates the value.
    </para>
    <note>
     <para>
      The value of the MySQL SQL function
      <literal>LAST_INSERT_ID()</literal> always contains the most
      recently generated AUTO_INCREMENT value, and is not reset
      between queries.
    </para>
    </note>
    <warning>
     <para>
      <function>mysql_insert_id</function> converts the return type of
      the native MySQL C API function
      <literal>mysql_insert_id()</literal> to a type of
      <literal>long</literal> (named <type>int</type> in PHP).
      If your AUTO_INCREMENT column has a column type of BIGINT,
      the value returned by <function>mysql_insert_id</function>
      will be incorrect. Instead, use the internal MySQL SQL function
      <literal>LAST_INSERT_ID()</literal> in an SQL query.
     </para>
    </warning>
    <example>
     <title>mysql_insert_id Example</title>
     <programlisting role="php">
<![CDATA[
<?php
    mysql_connect("localhost", "mysql_user", "mysql_password") or
        die("could not connect");
    mysql_select_db("mydb");

    mysql_query("INSERT INTO mytable (product) values ('kossu')");
    printf ("Last inserted record has id %d\n", mysql_insert_id());
?>
]]>
     </programlisting>
    </example>
    <para>
     See also: <function>mysql_query</function>.
    </para>
   </refsect1>
  </refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->