Home >Backend Development >PHP Tutorial >ThinkPHP writes array insertion and gets the latest inserted data ID method
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('数据写入错误!'); } }
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:
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!