ThinkPHP Write Array Insert and Get Latest Insert Data ID Instance
- 2021-07-24 10:23:09
- OfStack
This paper describes the implementation method of thinkphp writing array insertion and obtaining the latest insertion data ID. Share it for your reference. Specific methods are analyzed as follows:
This example shows how thinkphp writes array inserts itself, taking registered users as an example.
The specific implementation code is as follows:
public function insert2(){
header("Content-Type:text/html; charset=utf-8");
$Dao = M("User"); // Build an array of written data
$data["username"] = $_POST["username"];
$data["password"] = md5($_POST["password"];);
$data["email"] = $_POST["email"];
$data["regdate"] = time(); // Write data
if($lastInsId = $Dao->add($data)){ //$lastInsId Object for the most recently inserted data id
echo " Insert data id Is: $lastInsId";
} else {
$this->error(' Data write error! ');
}
}
I hope this article is helpful to everyone's ThinkPHP framework programming.