ThinkPHP writes array insertion and obtains the latest inserted data ID example, thinkphp example_PHP tutorial

WBOY
Release: 2016-07-13 10:15:27
Original
1004 people have browsed it

ThinkPHP write array insertion and get the latest inserted data ID example, thinkphp example

The example in 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 analysis is as follows:

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

The specific implementation code is as follows:

Copy code The code is as follows:
public function insert2(){
header("Content-Type:text/html; charset=utf-8");
$Dao = M("User"); // Construct the written data array
$data["username"] = $_POST["username"];
$data["password"] = md5($_POST["password"];);
$data["email"] = $_POST["email"];
$data["regdate"] = time(); // Write data
if($lastInsId = $Dao->add($data)){ //$lastInsId is the id of the latest inserted data
echo "Insert data id is: $lastInsId";
} else {
$this->error('Data writing error!');
}
}

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

thinkphp writes a piece of data and obtains the ID of the data

It’s very simple, if you have inserted successfully
$res=executes the insert statement;
if($res)
{
$session['id']=$res[ 'id']
Perform successful operation
}

Is there a function in thinkphp that returns the inserted data ID?

Generally inserting a piece of data will return the id of the data. You can directly define a variable to store it.
$map is an array
$id = D('User')->add( $map);
This $id is the id inserted into this data

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904923.htmlTechArticleThinkPHP writes array insertion and gets the latest inserted data ID example, thinkphp example This article tells the thinkphp write array insert and get The latest implementation method of inserting data ID. Share with everyone...
Related labels:
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