Home >PHP Framework >ThinkPHP >How to return the inserted data id in thinkphp5.0
添加数据后如果需要返回新增数据的自增主键,可以使用getLastInsID方法: Db::name('user')->insert($data); $userId = Db::name('user')->getLastInsID(); 或者直接使用insertGetId方法新增数据并返回主键值:Db::name('user')->insertGetId($data); insertGetId 方法添加数据成功返回添加数据的自增主键
thinkphp is a free development framework that can be used to develop front-end web pages. The earliest thinkphp was created to simplify development. thinkphp also follows the Apache2 protocol and was originally developed from Struts After evolution, it also makes use of some good foreign framework models, uses an object-oriented development structure, and is compatible with many tag libraries and other models. It can develop and deploy applications more conveniently and quickly, of course, not only enterprise-level applications, but also any Anyone developing PHP applications can benefit from thinkphp's simplicity, compatibility, and speed.
The above is the detailed content of How to return the inserted data id in thinkphp5.0. For more information, please follow other related articles on the PHP Chinese website!