ThinkPHP writes array insertion and gets the latest inserted data ID method

不言
Release: 2023-04-02 09:20:02
Original
3169 people have browsed it

This article mainly introduces ThinkPHP's method of writing array insertion and obtaining the latest inserted data ID. The example describes ThinkPHP's method of operating the database based on arrays, which has certain reference value. Friends in need can refer to it

The example of this article describes the implementation method of thinkphp writing array insertion and obtaining the latest inserted data ID. Share it with everyone for your reference. The specific method is analyzed as follows:

This example describes how thinkphp writes array insertion by itself. Here, a registered user is used as an example.

The specific implementation code is as follows:

public function insert2(){ 
 header("Content-Type:text/html; charset=utf-8"); 
 $Dao = M("User"); // 构建写入的数据数组
 $data["username"] = $_POST["username"];
 $data["password"] = md5($_POST["password"];);
 $data["email"] = $_POST["email"];
 $data["regdate"] = time(); // 写入数据
 if($lastInsId = $Dao->add($data)){  //$lastInsId为最新插入数据的id
 echo "插入数据 id 为:$lastInsId";
 } else {
 $this->error('数据写入错误!');
 }
 }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to the operation classes and usage of PHP’s full-featured non-deformation image cropping

ThinkPHP3.1 A more complete introduction to the new features’ support for Ajax

The above is the detailed content of ThinkPHP writes array insertion and gets the latest inserted data ID method. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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