Skip to content

Commit

Permalink
Update mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Oct 25, 2023
1 parent 60f1326 commit eeda7ab
Show file tree
Hide file tree
Showing 3 changed files with 317 additions and 168 deletions.
131 changes: 82 additions & 49 deletions reference/mysql/functions/mysql-info.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
<!-- EN-Revision: n/a Maintainer: dallas Status: ready -->
<refentry xml:id="function.mysql-info" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_info</refname>
<refpurpose>
取得最近一条查询的信息
</refpurpose>
</refnamediv>
<refsect1>
<title>说明</title>
<methodsynopsis>
<type>string</type><methodname>mysql_info</methodname>
<methodparam choice="opt"><type>resource</type><parameter>link_identifier</parameter></methodparam>
</methodsynopsis>
<!-- EN-Revision: e41806c30bf6975e452c0d4ce35ab0984c2fa68c Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.mysql-info" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_info</refname>
<refpurpose>获取最近查询的有关信息</refpurpose>
</refnamediv>

<refsynopsisdiv>
<warning>
&mysql.alternative.note;
<simplelist role="alternatives">
<member><function>mysqli_info</function></member>
</simplelist>
</warning>
</refsynopsisdiv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>mysql_info</methodname>
<methodparam choice="opt"><type>resource</type><parameter>link_identifier</parameter><initializer>NULL</initializer></methodparam>
</methodsynopsis>
<para>
返回最近一条查询的详细信息。
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.linkid.description;
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
在成功时返回语句信息,在失败时返回 &false;。请查看下面的示例,了解哪些语句提供信息,以及返回值可能是什么样子。未列出的语句将返回 &false;
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>相关的 MySQL 语句</title>
<para>
<function>mysql_info</function>
返回通过给定的
<parameter>link_identifier</parameter>
所进行的最新一条查询的详细信息。如果没有指定
<parameter>link_identifier</parameter>,则假定为上一个打开的连接。
返回字符串值的语句。这些数字仅用于说明目的;它们的值将与查询相对应。
</para>
<para>
<function>mysql_info</function>
对以下列出的所有语句返回一个字符串。对于其它任何语句返回
&false;。字符串的格式取决于给出的语句。
<example>
<title>相关的 MySQL 语句</title>
<programlisting role="mysql">
<programlisting role="mysql">
<![CDATA[
INSERT INTO ... SELECT ...
字符串格式:Records: 23 Duplicates: 0 Warnings: 0
String format: Records: 23 Duplicates: 0 Warnings: 0
INSERT INTO ... VALUES (...),(...),(...)...
字符串格式:Records: 37 Duplicates: 0 Warnings: 0
String format: Records: 37 Duplicates: 0 Warnings: 0
LOAD DATA INFILE ...
字符串格式:Records: 42 Deleted: 0 Skipped: 0 Warnings: 0
String format: Records: 42 Deleted: 0 Skipped: 0 Warnings: 0
ALTER TABLE
字符串格式:Records: 60 Duplicates: 0 Warnings: 0
String format: Records: 60 Duplicates: 0 Warnings: 0
UPDATE
字符串格式:Rows matched: 65 Changed: 65 Warnings: 0
String format: Rows matched: 65 Changed: 65 Warnings: 0
]]>
</programlisting>
</example>
上例中的数字只是为了演示的目的,实际的值取决于查询。
</para>
<note>
<para>
<function>mysql_info</function>
对于
INSERT ... VALUES
语句仅在该语句中列出了多个值的情况下返回一个非 &false; 的值。
</para>
</note>
<para>
参见 <function>mysql_affected_rows</function>。
</para>
</refsect1>
</refentry>
</programlisting>
</example>
</para>
</refsect1>

<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
<function>mysql_info</function> 对于 INSERT ... VALUES
语句仅在该语句中列出了多个值的情况下返回非 &false; 的值。
</para>
</note>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>mysql_affected_rows</function></member>
<member><function>mysql_insert_id</function></member>
<member><function>mysql_stat</function></member>
</simplelist>
</para>
</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
Expand Down
173 changes: 105 additions & 68 deletions reference/mysql/functions/mysql-insert-id.xml
Original file line number Diff line number Diff line change
@@ -1,78 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
<!-- EN-Revision: n/a Maintainer: dallas Status: ready -->
<refentry xml:id="function.mysql-insert-id" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_insert_id</refname>
<refpurpose>
取得上一步 INSERT 操作产生的 ID
</refpurpose>
</refnamediv>
<refsect1>
<title>说明</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>
返回给定的
<parameter>link_identifier</parameter>
中上一步 INSERT 查询中产生的 AUTO_INCREMENT 的 ID 号。如果没有指定
<parameter>link_identifier</parameter>,则使用上一个打开的连接。
</para>
<para>
如果上一查询没有产生
AUTO_INCREMENT 的值,则
<function>mysql_insert_id</function>
返回 0。如果需要保存该值以后使用,要确保在产生了值的查询之后立即调用
<function>mysql_insert_id</function>。
</para>
<note>
<para>
MySQL 中的 SQL 函数
<literal>LAST_INSERT_ID()</literal>
总是保存着最新产生的
AUTO_INCREMENT 值,并且不会在查询语句之间被重置。
</para>
</note>
<warning>
<para>
<function>mysql_insert_id</function> 将
MySQL 内部的 C API 函数
<literal>mysql_insert_id()</literal>
的返回值转换成
<literal>long</literal>(PHP 中命名为 <type>int</type>)。如果
AUTO_INCREMENT 的列的类型是 BIGINT,则
<function>mysql_insert_id</function>
返回的值将不正确。可以在 SQL 查询中用
MySQL 内部的 SQL 函数
<literal>LAST_INSERT_ID()</literal> 来替代。
</para>
</warning>
<para>
<example>
<title><function>mysql_insert_id</function> 例子</title>
<programlisting role="php">
<!-- EN-Revision: 4754397753fd79f1c846868b66a2448babab1c54 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.mysql-insert-id" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_insert_id</refname>
<refpurpose>取得上一条查询生成的 ID</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>
检索通过之前查询(通常是 INSERT)中 AUTO_INCREMENT 列生成的 ID。
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.linkid.description;
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
成功时返回通过之前查询中 AUTO_INCREMENT 列生成的 ID,如果之前查询没有生成 AUTO_INCREMENT
值,则为 <literal>0</literal>。如果没有建立 MySQL 连接,则为 &false;
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>mysql_insert_id</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$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());
mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>
]]>
</programlisting>
</example>
</para>
<para>
参见 <function>mysql_query</function>。
</para>
</refsect1>
</refentry>
</programlisting>
</example>
</para>
</refsect1>

<refsect1 role="notes">
&reftitle.notes;
<caution>
<para>
<function>mysql_insert_id</function> will convert 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 (64 bits) the
conversion may result in an incorrect value. Instead, use the internal
MySQL SQL function LAST_INSERT_ID() in an SQL query. For more information
about PHP's maximum integer values, please see the
<link linkend="language.types.integer">integer</link> documentation.
</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:
Expand Down
Loading

0 comments on commit eeda7ab

Please sign in to comment.