mysql_insert_id()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjayis
    New Member
    • Mar 2008
    • 134

    mysql_insert_id()

    hi

    i have a form which inserts records into my table using php

    and to get the inserted id(auto_increme nted ID) can i use this command?

    Code:
    <?
    mysql_query(“insert into table(name,value) values('$name','value')”); 
    
    echo "Auto increment ID is = ".mysql_insert_id(); 
    ?>

    if multiple users are using the same page and multiple datas are inserted at a single time ., will it return the unique Auto_increment ID for the particular record or will it return the last inserted id...

    thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by vjayis
    and to get the inserted id(auto_increme nted ID) can i use this command?
    Originally posted by php.net
    Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
    Originally posted by vjayis
    if multiple users are using the same page and multiple datas are inserted at a single time .,
    not possible, and even if 2 people could manage to make a request at the same microsecond, it will be queued (I think)

    Originally posted by vjayis
    will it return the unique Auto_increment ID for the particular record or will it return the last inserted id...
    what does your logic tells you will happen?

    Comment

    • charli
      New Member
      • Nov 2008
      • 23

      #3
      Hmm, the mysql documentation does use language thats a bit hazy on that doesn't it.

      Mysql_insert_id () looks at the current connection, so should always returns the relevant value with no concurrency issues

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by MySQL.com
        Using LAST_INSERT_ID( ) and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.
        Now, are multiple connections from PHP considered 'multiple clients'?

        Maybe a question for MySQL forum.

        Comment

        Working...