Home  >  Article  >  PHP Framework  >  What is the return value of the add method in thinkphp

What is the return value of the add method in thinkphp

WBOY
WBOYOriginal
2022-02-25 12:06:413757browse

The return value of the add() method in thinkphp: 1. "ID of inserted data". When the ID of inserted data is returned, it means that the method has successfully inserted data; 2. "false", when false is returned , it means that the method failed to insert data.

What is the return value of the add method in thinkphp

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

What is the return value of the add method in thinkphp

ThinkPHP's built-in add method is used to add data to the data table, which is equivalent to the INSERT INTO behavior in SQL.

Usage examples are as follows:

$User = M("User"); // 实例化User对象
$data['name'] = 'ThinkPHP';
$data['email'] = 'ThinkPHP@gmail.com';
$User->add($data);

Or use the data method to operate continuously

$User->data($data)->add();

If the data object has been created before add (for example, the create or data method is used), add The method no longer needs to pass in data.

When the add() method succeeds, it returns the id of the inserted data. When it fails, it returns false.

That is to say, when we judge whether add() is successful, we only need to judge whether the result is equal to false

if($result===false){
echo "添加失败!";
}else{
echo "添加成功";
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the return value of the add method in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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