C API Function Descriptions
2162
•
INSERT
statements that store a value into an
AUTO_INCREMENT
column. This is true whether the
value is automatically generated by storing the special values
NULL
or
0
into the column, or is an
explicit nonspecial value.
• In the case of a multiple-row
INSERT
statement,
mysql_insert_id()
returns the first
automatically generated
AUTO_INCREMENT
value; if no such value is generated, it returns the last
explicit value inserted into the
AUTO_INCREMENT
column.
If no rows are successfully inserted,
mysql_insert_id()
returns 0.
• Starting in MySQL 5.0.54, if an
INSERT ... SELECT
statement is executed, and no automatically
generated value is successfully inserted,
mysql_insert_id()
returns the ID of the last inserted
row.
•
INSERT
statements that generate an
AUTO_INCREMENT
value by inserting
LAST_INSERT_ID(expr)
[961]
into any column or by updating any column to
LAST_INSERT_ID(expr)
[961]
.
• If the previous statement returned an error, the value of
mysql_insert_id()
is undefined.
mysql_insert_id()
returns
0
if the previous statement does not use an
AUTO_INCREMENT
value.
If you need to save the value for later, be sure to call
mysql_insert_id()
immediately after the
statement that generates the value.
The value of
mysql_insert_id()
is not affected by statements such as
SELECT
that return a result
set.
The value of
mysql_insert_id()
is affected only by statements issued within the current client
connection. It is not affected by statements issued by other clients.
The
LAST_INSERT_ID()
[961]
SQL function returns the most recently generated
AUTO_INCREMENT
value, and is not reset between statements because the value of that function is maintained in the
server. Another difference from
mysql_insert_id()
is that
LAST_INSERT_ID()
[961]
is not
updated if you set an
AUTO_INCREMENT
column to a specific nonspecial value. See
Section 12.13,
“Information Functions”
.
mysql_insert_id()
returns
0
following a
CALL
statement for a stored procedure that generates
an
AUTO_INCREMENT
value because in this case
mysql_insert_id()
applies to
CALL
and not the
statement within the procedure. Within the procedure, you can use
LAST_INSERT_ID()
[961]
at the
SQL level to obtain the
AUTO_INCREMENT
value.
The reason for the differences between
LAST_INSERT_ID()
[961]
and
mysql_insert_id()
is that
LAST_INSERT_ID()
[961]
is made easy to use in scripts while
mysql_insert_id()
tries to provide
more exact information about what happens to the
AUTO_INCREMENT
column.
Return Values
Described in the preceding discussion.
Errors
None.
20.6.6.38.
mysql_kill()
int mysql_kill(MYSQL *mysql, unsigned long pid)
Description
Asks the server to kill the thread specified by
pid
.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...