Get field value of inserted row

后端 未结 1 419
忘掉有多难
忘掉有多难 2021-01-23 12:38

I want to write a function that returns the value of a column (in this case, an auto-incrementing primary key) for a row that it inserts.

Essentially, I want to insert s

1条回答
  •  花落未央
    2021-01-23 13:15

    As pointed in the comments, from MySQL documentation:

    mysql> SELECT LAST_INSERT_ID();
        -> 195
    

    This LAST_INSERT_ID() function is not subject to a race condition like SELECT MAX(id) might be, because it's maintained within MySQL specific to your connection. It returns the ID generated for your last insert, not anybody's last insert.

    0 讨论(0)
提交回复
热议问题