php-doc-en/reference/mysql/functions/mysql-insert-id.xml
Hannes Magnusson c030e2adf7 Upgrade to DocBook5:
- All id attributes are now xml:id
 - Add docbook namespace to all root elements
 - Replace <ulink /> with <link xlink:href />
 - Minor markup fixes here and there


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@238160 c90b9560-bf6c-de11-be94-00142212c4b1
2007-06-20 22:25:43 +00:00

124 lines
3.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.mysql-insert-id" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_insert_id</refname>
<refpurpose>Get the ID generated from the previous INSERT operation</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>mysql_insert_id</methodname>
<methodparam choice="opt"><type>resource</type><parameter>link_identifier</parameter></methodparam>
</methodsynopsis>
<para>
Retrieves the ID generated for an AUTO_INCREMENT column by the previous
INSERT query.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.linkid.description;
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The ID generated for an AUTO_INCREMENT column by the previous
INSERT query on success, <literal>0</literal> if the previous
query does not generate an AUTO_INCREMENT value, or &false; if
no MySQL connection was established.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>mysql_insert_id</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
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>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<caution>
<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>
</caution>
<note>
<para>
Because <function>mysql_insert_id</function> acts on the last performed
query, be sure to call <function>mysql_insert_id</function> immediately
after the query that generates the value.
</para>
</note>
<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>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>mysql_query</function></member>
<member><function>mysql_info</function></member>
</simplelist>
</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
-->