Yii2.0 database query operation

Source: Internet
Author: User
The following describes some simple operations of Yii2.0 on database query. The following describes some simple operations of Yii2.0 on database query.

User: find ()-> all (); this method returns all data; User: findOne ($ id ); this method returns a piece of data with primary key id = 1 (for example); User: find ()-> where (['name' => 'hangzhou']) -> one (); this method returns a piece of data from ['name' => 'users']; User: find () -> where (['name' => 'hangzhou'])-> all (); this method returns all data of ['name' => 'hangzhou']; 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 an SQL statement to query a piece of data in the user table. User: find ()-> andWhere (['sex' => 'male ', 'age' => '24'])-> count ('id'); total number of qualified items; User: find ()-> one (); this method returns a data entry; 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 value 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 (); the query result of the first column of the first row returned by this method; User: find ()-> column (); this method returns the value of the first column in the query result; User :: find ()-> exists (); this method returns a value indicating whether the data row contains the query result; User: find ()-> batch (10 ); obtain 10 data records each time. User: find ()-> each (10); 10 data records each time, iterative query

Yii provides us with a wealth of 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.