PHP/MySQL insert row then get 'id'

前端 未结 10 1047
臣服心动
臣服心动 2020-11-22 16:03

The \'id\' field of my table auto increases when I insert a row. I want to insert a row and then get that ID.

I would do it just as I said it, but is there a way I c

10条回答
  •  长情又很酷
    2020-11-22 16:25

    The MySQL function LAST_INSERT_ID() does just what you need: it retrieves the id that was inserted during this session. So it is safe to use, even if there are other processes (other people calling the exact same script, for example) inserting values into the same table.

    The PHP function mysql_insert_id() does the same as calling SELECT LAST_INSERT_ID() with mysql_query().

提交回复
热议问题