Is there a way to return the id of a row that was just created in MySQL with PHP?

前端 未结 6 1909
Happy的楠姐
Happy的楠姐 2021-01-19 09:52

When I create a new entry in my MySQL database, I\'d like the query to return the id of the table that was just created. If it cannot do this, is there another way to find

6条回答
  •  感情败类
    2021-01-19 10:21

    You have LAST_INSERT_ID() in My SQL (@@IDENTITY in ms sql) and mysql_insert_id in php.

    Personally though, I try to avoid auto increments / identity columns and generate my id's in other ways. Amongst other reasons, because they make inserts into multiple tables harder.

    /B

提交回复
热议问题