Here's a look at some of Yii2.0 's simple operations on database queries

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.