List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 3 1999 2:20pm
Subject:Re: mysql_insert_id()
View as plain text  
At 11:16 PM -0500 6/2/99, Michael Widenius wrote:
>Hi!
>
>>>>>> "Benjamin" == Benjamin Pflugmann <philemon@stripped>
> writes:
>
>Benjamin> Hi.
>Benjamin> Without looking at the source, it sounds to me as if the server
>Benjamin> sends/updates the value of mysql_insert_id() only if it was
>changed on
>Benjamin> the server.
>
><cut>
>
>Yes, this is right;  The client side 'mysql_insert_id' is updated for
>each query and set to 0 if you didn't use an insert statement with a
>auto_increment column.
>The server side LAST_INSERT_ID() is only changed when on updates a
>auto_increment column() or executes LAST_INSERT_ID(value).
>
>Regards,
>Monty


I will change the manual so it says the following, which I hope is clearer.

>@code{my_ulonglong mysql_insert_id(MYSQL *mysql)}
>
>@subsubheading Description
>
>Returns the ID generated for an @code{AUTO_INCREMENT} column by the previous
>query.  Use this function after you have performed an @code{INSERT} query
>into a table that contains an @code{AUTO_INCREMENT} field.
>
>Note that @code{mysql_insert_id()} returns @code{0} if the previous query
>does not generate an @code{AUTO_INCREMENT} value.  If you need to save
>the value for later, be sure to call @code{mysql_insert_id()} immediately
>after the query that generates the value.
>
>Also note that the value of the SQL @code{LAST_INSERT_ID()} function always
>contains the most recently generated @code{AUTO_INCREMENT} value, and is
>not reset between queries since the value of that function is maintained
>in the server.
>
>@subsubheading Return values
>
>The value of the @code{AUTO_INCREMENT} field that was updated by the previous
>query.  Returns zero if there was no previous query on the connection or if
>the query did not update an @code{AUTO_INCREMENT} value.

--
Paul DuBois, paul@stripped
Northern League Chronicles: http://www.snake.net/nl/
Thread
mysql_insert_id()Matthias Pigulla1 Jun
  • Re: mysql_insert_id()Paul DuBois1 Jun
    • Re: mysql_insert_id()Matthias Pigulla3 Jun
      • Re: mysql_insert_id()Paul DuBois3 Jun
    • Re: mysql_insert_id()Jim Faucette3 Jun
    • Re: mysql_insert_id()Matthias Pigulla3 Jun
      • Re: mysql_insert_id()Benjamin Pflugmann3 Jun
        • Re: mysql_insert_id()Michael Widenius3 Jun
          • Re: mysql_insert_id()Paul DuBois3 Jun
    • Re: mysql_insert_id()Matthias Pigulla3 Jun
    • Re: mysql_insert_id()Matthias Pigulla3 Jun
      • Re: mysql_insert_id()Michael Widenius3 Jun