Home > Article > Backend Development > Summary of related content about database operation return values in ThinkPHP
Reprinted from: Summary of database operation return values in ThinkPHP
Keywords: Thinkphp, return value, database operation, select return value, add return value, setDec return value
Thinkphp in The Think\Model class provides the basic CURD (Create, Update, Read and Delete) of the database, which can be easily operated through this class.
The main methods of Model class and extension class are:
Create operation:
create() (non-chain), add(), addAll()
Supported chain operations include:
table, data, field, relation, validate, auto, filter, scope, bind, token, comment
save( ), setField(), setInc(), setDec()
Supported chain operations are:
where, table, alias, field, order, lock, relation, scope, bind, comment
find(), select(), getField(), Count, Max, Min, Avg, Sum
Supported chain operations are:
where, table, alias, field, order, group, having, join, union, distinct, lock, cache, relation, result, scope, bind, comment
delete()
Supported chain operations include:
where, table, alias, order, lock, relation, scope, bind, comment
1. Chain operation:
$User=M("User"); $U1=$User->$where("id = 1");//$U1可以继续调用其他方法。 $result=$U1->select(); //-------一般情况下没有必要这样,下面一句代码即可实现 $result=M("User")->$where("id = 1")->select();
2. Create operation
If an error occurs, false is returned;
If successful, the created data is returned
create It is a non-chain operation, and the return value may be a Boolean value, so strict judgment must be made during the operation:$User = M("User"); if($User->create()){ //进行更多操作 }
If the query result If it is empty, NULL is returned. If the query is successful, an associative array is returned (the key value is the field name or alias).
If the query result is empty, NULL is returned, otherwise a two-dimensional array is returned.
If the query is successful, the corresponding value is returned
This article explains the summary of the return value of database operations in ThinkPHP. For more related content, please visit Follow php Chinese website.
related suggestion:
Related content about thinkphp base class
ThinkPHP users Login and registration related code cases
About thinkphp5 database operations
##
The above is the detailed content of Summary of related content about database operation return values in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!