Mysql last_insert_id() - help

Discussion in 'MySQL' started by tamilsoft, Mar 17, 2008.

  1. #1
    Hi,

    Is it possible to get the last_insert_id() in mysql at any time?, means without doing any insertion.

    Thanks in advance
    tamilsoft
     
    tamilsoft, Mar 17, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    It should be. It returns the key for the last inserted record. I think you do need to specify the table that you would like the id from though.
     
    jestep, Mar 18, 2008 IP
  3. dman_2007

    dman_2007 Peon

    Messages:
    1,259
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, it is not possible. last_insert_id() returns the latest automatically generated value while doing a new insert using the current connection otherwise it returns 0.
     
    dman_2007, Mar 20, 2008 IP