locked
LAST_INSERT_ID() on which Connection? RRS feed

  • Question

  • User102459681 posted

    Hi Folks,

    I would like to use the SELECT LAST_INSERT_ID() statement i MySQL to get the last auto-incremented id.

    The documentation says:  the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. 


    My Questions is what is considered a connection.... each time my web sever connects to the mysql sever it's considerd a different connection correct?

    I't's a different connection even if it comes from the same web server? Even if in Asp.net the connection has the same name?
    i.e ( Dim myConnection2 As New MySqlConnection(connectionString2))

    Will different instances of the above connection example be considered as different connections by MySQL?
    If different sessions of my web application are all connecting to the MySQL db with the above connection definition each session will be considered as seperate connection by MySQL?

    What I'm concerned about is if somehow my different web sessions use the same connection and therefore it would break the logic of the SELECT LAST_INSERT_ID() and one user would fetch another one's ID...



    Regards,
    Andy 


    Sunday, February 26, 2012 12:05 PM

Answers

  • User-821857111 posted

    each time my web sever connects to the mysql sever it's considerd a different connection correct?

    Correct.

    Will different instances of the above connection example be considered as different connections by MySQL?
    Yes.
    if somehow my different web sessions use the same connection
    Can't happen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 26, 2012 3:30 PM