Case Analysis of add method in thinkphp
This article mainly introduces the relevant knowledge of add method case analysis in thinkphp, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will have something to gain after reading this thinkphp add method case analysis article. Let's take a look.
The return value of the add () method in thinkphp: 1, "ID of inserting data", when the ID of inserting data is returned, it means that the method inserted data successfully; 2, "false", when false is returned, it indicates that the method has failed to insert data.
This article operating environment: Windows10 system, ThinkPHP5 version, 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.
Examples of use are as follows:
$User = M ("User"); / / instantiate the User object $data ['name'] =' ThinkPHP';$data ['email'] =' ThinkPHP@gmail.com';$User- > add ($data)
Or use the data method to operate coherently
$User- > data ($data)-> add ()
If the data object has been created before add (for example, using the create or data method), the add method does not need to pass in any more data.
When the add () method succeeds, it returns the id that inserted the data, and 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 "add failed!" ;} else {echo "added successfully";} this article on "add method instance Analysis in thinkphp" ends here. Thank you for reading! I believe you all have a certain understanding of the knowledge of "case Analysis of add method in thinkphp". If you want to learn more, you are welcome to follow the industry information channel.