Home >PHP Framework >ThinkPHP >What is the return value of the add method in thinkphp
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.
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
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!