search
HomePHP FrameworkThinkPHPHow 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 方法添加数据成功返回添加数据的自增主键

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:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software