Files
php-doc-ru/reference/mysql/functions/mysql-insert-id.xml
George Peter Banyard f192aaffda Update EN-Revision tags for new rev-check
This only updates files which have an empty diff between the two different revisions
2021-02-02 18:35:21 +00:00

138 lines
4.8 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 65e697ff671608989432a6e6bf8ae8128b2be2c7 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<!-- $Revision$ -->
<refentry xml:id="function.mysql-insert-id" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_insert_id</refname>
<refpurpose>Возвращает идентификатор, сгенерированный при последнем INSERT-запросе</refpurpose>
</refnamediv>
<refsynopsisdiv>
<warning>
&mysql.alternative.note;
<simplelist role="alternatives">
<member><function>mysqli_insert_id</function></member>
<member><methodname>PDO::lastInsertId</methodname></member>
</simplelist>
</warning>
</refsynopsisdiv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>mysql_insert_id</methodname>
<methodparam choice="opt"><type>resource</type><parameter>link_identifier</parameter><initializer>NULL</initializer></methodparam>
</methodsynopsis>
<para>
Возвращает идентификатор, сгенерированный колонкой с AUTO_INCREMENT
последним запросом (обычно INSERT).
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.linkid.description;
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Идентификатор, сгенерированный колонкой с AUTO_INCREMENT
последним запросом в случае успеха , <literal>0</literal>, если
последний запрос не генерирует значение AUTO_INCREMENT value, и
&false;, если соединение MySQL не было установлено.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>mysql_insert_id</function></title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Ошибка соединения: ' . mysql_error());
}
mysql_select_db('mydb');
mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Идентификатор последней вставленной записи %d\n", mysql_insert_id());
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<caution>
<para>
<function>mysql_insert_id</function> конвертирует возвращаемый функцией
MySQL C API тип значения функции <literal>mysql_insert_id()</literal> в
тип <literal>long</literal> (называемый <type>int</type> в PHP).
Если ваша колонка AUTO_INCREMENT имеет тип BIGINT (64 бита), то значение,
возвращаемое функцией в результате преобразования может быть
искажено. Используйте вместо данной функции внутреннюю MySQL-функцию
LAST_INSERT_ID() в SQL-запросе. Подробнее о
максимальных значениях целых чисел смотрите в
<link linkend="language.types.integer">разделе документации,
посвящённом целым числам</link>.
</para>
</caution>
<note>
<para>
Так как <function>mysql_insert_id</function> работает с последним
выполненным запросом, вызывайте <function>mysql_insert_id</function>
сразу же после запроса, генерирующего новое значение.
</para>
</note>
<note>
<para>
Значение в SQL функции MySQL
<literal>LAST_INSERT_ID()</literal> всегда содержит последний
сгенерированный ID и не обнуляется между запросами.
</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:"~/.phpdoc/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
-->