Categories
不学无术 木有技术

MYSQL获取自增ID

参考:
http://flandycheng.blog.51cto.com/855176/280224
http://www.cnblogs.com/badtree/articles/2143103.html
http://my.oschina.net/fz04003/blog/63327
比较简单的方法是:
insert/select…等操作
然后直接下一条语句:

SELECT LAST_INSERT_ID()

LAST_INSERT_ID 是与table无关的,如果向表a插入数据后,再向表b插入数据,LAST_INSERT_ID会改变。
看参考文献中说,多用户的情况下这个方法不能用。不过在php环境下,单用户用足够的。
 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.