开发者

how to select last autoincrement id using php and mysql [duplicate]

开发者 https://www.devze.com 2023-02-23 16:59 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: php/MySQL insert row then get 'id'
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

php/MySQL insert row then get 'id'

I have a开发者_C百科n inset command such as

insert (name) values($name);

I have id column as autoincrement. How can I get the id of the inserted record after inserting.


insert (name) values($name);
SET @lastid = LAST_INSERT_ID();
select blah_blah from table where id = @lastid;

To get that back into php, you do a normal mysql select on it like this:

select @lastid;


For mysql you can use mysql_insert_id to get the id of the last inserted row.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号