Here's a look at some of Yii2.0 's simple operations on database queries
User::find ()->all (); This method returns all data; User::findone ($id); This method returns a single piece of data for the primary key id=1 (for example), User::find ()->where ([' name ' = ' ' lad '])->one (); This method returns a data of [' name ' = ' lad '], User::find ()->where ([' name ' = ' ' lad '])->all (); This method returns all data for [' name ' = ' lad '], User::find ()->orderby (' id DESC ')->all (); This method is a sort query; User::findbysql (' SELECT * from User ')->all (); This method uses SQL statements to query all data in the user table, User::findbysql (' SELECT * from user ')->one (); This method uses the SQL statement to query a data in the user table, User::find ()->andwhere ([' sex ' = ' male ', ' age ' = '] ')->count (' id '); Statistics of the total number of bars that meet the conditions; User::find ()->andfilterwhere ([' Like ', ' name ', ' lad ']); This method is using the like query name equals the data of the Lad User::find ()->one (); This method returns a piece of data; User::find ()->all (); This method returns all data; User::find ()->count (); This method returns the number of records; User::find ()->average (); This method returns the average of the specified column; User::find ()->min (); This method returns the minimum value of the specified column; User::find ()->max (); This method returns the maximum value of the specified column; User::find ()->scalar (); This method returns the query result for the first column of the first row of the value; User::find ()->column (); This method returns the first column in the query resultsThe value of User::find ()->exists (); This method returns a value indicating whether the data row contains the query results; User::find ()->batch (10); Fetch 10 Data User::find ()->each (10) at a time; 10 data per fetch, iterative query
Here are some simple things to do with Yii2.0 database queries