如何在mysql中获取下一个自动增量ID [英] How to get the next auto-increment id in mysql

查看:183
本文介绍了如何在mysql中获取下一个自动增量ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取mysql中的下一个ID以便将其插入表中

How to get the next id in mysql to insert it in the table

INSERT INTO payments (date, item, method, payment_code)
VALUES (NOW(), '1 Month', 'paypal', CONCAT("sahf4d2fdd45", id))

推荐答案

使用

Use LAST_INSERT_ID() from your SQL query.

您还可以使用 mysql_insert_id() 来通过PHP进行获取.

You can also use mysql_insert_id() to get it using PHP.

这篇关于如何在mysql中获取下一个自动增量ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆