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

How to return the inserted data id in thinkphp5.0

WBOY
Release: 2023-05-28 22:40:14
forward
3400 people have browsed it
添加数据后如果需要返回新增数据的自增主键,可以使用getLastInsID方法:
Db::name('user')->insert($data);
 $userId = Db::name('user')->getLastInsID();
 或者直接使用insertGetId方法新增数据并返回主键值:Db::name('user')->insertGetId($data);
 insertGetId 方法添加数据成功返回添加数据的自增主键
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template