Home  >  Article  >  PHP Framework  >  How to return the inserted data id in thinkphp5.0

How to return the inserted data id in thinkphp5.0

WBOY
WBOYforward
2023-05-28 22:40:143346browse
添加数据后如果需要返回新增数据的自增主键,可以使用getLastInsID方法:
Db::name('user')->insert($data);
 $userId = Db::name('user')->getLastInsID();
 或者直接使用insertGetId方法新增数据并返回主键值:Db::name('user')->insertGetId($data);
 insertGetId 方法添加数据成功返回添加数据的自增主键

What is thinkphp

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Why use thinkphp?Next article:Why use thinkphp?