ThinkPHP_5: Database CURL operation, thinkphp_5curl
Db: query ();
Db: execute ();
Db: table ()-> select (); all data, two-dimensional array. If the result does not exist, an empty array is returned.
Db: table-> find (); one piece of data, one-dimensional array. If the result does not exist, NULL is returned.
Db: table-> value (); a piece of data. If the result does not exist, null is returned.
Db: table-> column (); returns a one-dimensional array. If there is a second parameter, returns an array identified by the second number. If the result does not exist, NULL is returned.
Db: table ()->... table name and table prefix
Db: name ()-> .. ignore table prefix
// Add data [array]
Db: name ()-> insert (); the number of affected rows is returned.
Db: name ()-> insertGetId (); get the last new id
Db: name ()-> insertAll (); insert all data
// Update the database [array]
Db: name ()-> where ()-> update (); the number of affected rows is returned.
Db: name ()-> where ()-> setField ('name', 'xiaomi '); the number of affected rows returned by a field of updated data
Db: name ()-> where-> setInc ('num'); num field name increases by 1 each time
Db: name ()-> where-> setInc ('num', 5); num Field Names increase by 5 each time
Db: name ()-> where ()-> setDec ('num'); each time the num field is auto-subtracted
Delete
Db: name ()-> where ()-> delete (); the number of affected rows is returned.
If you want to delete a primary key, you can leave the where
Db: name ()-> delete (1); delete records with id = 1
Condition Constructor
Db: name ()-> where ()-> buildSql (); returns an SQL statement
Db: name ()-> where ("id = 1")-> buildSql (); Transfer Condition
Db: name ()-> where ("id", 1)-> buildSql (); pass the field name and the expected value
Db: name ()-> where ("id", "<>", 1)-> buildSql (); field name, expression, value to be determined
Db: name ()-> where ('id', 'between', '1, 5')-> buildSql (); IDs between 1 and 5, including 1 and 5
Db: name ()-> where (['id' => 1])-> buildSql ();
Db: name ()-> where (['id' => ['in', [1, 2, 4])-> buildSql ();
[Relationship between the two conditions: and]
Db: name ()-> where (
['Id' => 1],
['Name' => 'kaluo ']
)-> BuildSql ();
EXP is a conditional expression.
Db: name ()-> where ("id", "EXP", "not in (1, 2, 3)")-> buildSql ();
[The relationship between the two conditions is or]
Db: name ()-> where ("id", "in", "1, 2, 3")-> whereOr ('name', 'buld ') -> buildSql ();
Where () contains arrays, strings, and parameters.
# Remarks [uppercase and lowercase letters are translated into subsequent symbols] [the conditions are case insensitive]
# EQ =
# NEQ <>
# LT <
# ELT <=
# GT>
# EGT> =
# BETWEEN * AND *
# Notbetween not between * AND *
# IN (*,*)
# Notin no tin (*,*)
Expression ::
Between
In
Chain Operation
Db: table ()-> where ('id', '>', 10)-> select (); all fields in the queried table
Field Method]
Db: table ()-> where ('id', '>', 10)-> field ("name, id")-> select (); query the name in the table, id field
[Order method]
Db: table ()-> where ('id', '>', 10)-> field ("name, id")-> order ("id DESC ") -> limit ()-> select (); query the name, id field, and reverse sorting In the table. The value starts from the third and takes 5.
[Page Method] [page () displays five items starting from page 2]
Db: table ()-> where ('id', '>', 10)-> field ("name, id")-> order ("id DESC ") -> page ()-> select (); query the name, id field, and reverse sorting In the table. Obtain 5 records from the third page.
[Group]
Db: table ()-> where ('id', '>', 10)-> field ("name, id")-> group ("'group '") -> select (); query the name and id fields in the table, grouped by group