Results 1 to 8 of 8

Thread: Last_insert_id

  1. #1
    Join Date
    Jul 2010
    Location
    ISHHHH
    Posts
    130

    Unanswered: Last_insert_id

    can we use this command to get the last inserted values or else we had to use max() option but when i try with this command it showing the last inserted values with respected to the no.of columns nothing but duplicate rows LAST_INSERT_ID
    WiTh Tnks & ReGaRdS
    mAtHuKuMaLi

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    last insert id will return the last autogenerated id assuming that you didn't try to pass a value yourself
    MySQL :: MySQL 5.0 Reference Manual :: 19.8.10.3 How to Get the Unique ID for the Last Inserted Row
    but bear in mind in a multi user db the results may not be as expected, you may need to secure a lock to write the data and then retrieve the id then release the lock.

    however it is language specific....
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2010
    Location
    ISHHHH
    Posts
    130
    thanks healdem you are helping me a lot in this forum a small cheers
    WiTh Tnks & ReGaRdS
    mAtHuKuMaLi

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by healdem View Post
    but bear in mind in a multi user db the results may not be as expected...
    the page you linked to contradicts this
    Quote Originally Posted by da manual
    For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    It depends on which language you are retrieving the last ID in. Im pretty certain thats not the case when retrieving the3 ID under PHP
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    that's funny, i recall this same question on several forums many times, and it was always php, and it wasn't just me saying that it's guaranteed...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    PHP isn't a structured language written from the ground up
    it started as a a glue language for web applications

    its terrifically easy to write bad code in PHP, in many ways reminiscent of the early days of BASIC before it went all object orientated in .NET.

    its just grown without any formal development strictures.
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    and this influences the behaviour of a mysql function how?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •