Model for data operations, inherited from cactiverecord (Active Records)
The ar database is encapsulated upwards, and Ar operates the database through OOP object-oriented method. Ar needs to be eventually converted to a specific SQL statement, and is assisted by an intermediate class (criteria standard. Find and findall are some attributes of this class.
File Path AR: \ framework \ dB \ Ar \ cactiverecord. php
You can see many methods
Open the findall function and track the \ framework \ dB \ schema \ cdbcommandbuilder. php file in the class library.
Trace the file \ framework \ dB \ schema \ cdbcriteria. php again:
Why is this tracing:
1
2
3
Common Query Method
The following are three query methods:
Function actionceshi () {$ model = goods: Model (); // $ Infos = $ model-> findallbypk (10 ); // $ Infos = $ model-> findallbypk (Array (1, 5, 12 )); //////////////////////////////////////// //////////////////////////////////////// /// // findall ($ condition, $ PARAM) // $ condition is the where condition of the SQL statement // query the Nokia mobile phone at a price greater than 500 RMB // $ Infos = $ model-> findall ("goods_name like 'non%' and goods_price> 500 "); // to avoid SQL Injection security problems, it is recommended that you do not directly write the condition information in the SQL statement // $ Infos = $ model-> findall ("goods_name like: Name and goods_price>: price ", array (': name' => 'non' %', ': price' => 500 )); //////////////////////////////////////// //////////////////////////////////////// ///// // You can query the information, // You Want to query the specific "field" select // You Want to query the specific "condition" condition // You Want to query the specific "sort" Order // You Want to query the specific "group "// You Want to query the specific "Limit" Limit // You Want to query the specific "offset" offset // $ Infos = $ model-> findall (Array (// 'select' => 'Goods _ name, goods_price ', // 'condition' => "goods_name like 'non' % '", // 'order' => 'goods _ price desc ', // 'limit' => 3, // 'offset' => 6 ,//)); //////////////////////////////////////// //////////////////////////////////////// ///// // use criteria to query information. $ criteria = new cdbcriteria (); $ criteria-> select = "goods_name, goods_price"; $ criteria-> condition = "goods_name like 'mo % '"; // $ criteria-> Limit = 6; $ criteria-> order = "goods_price"; $ Infos = $ model-> findall ($ criteria); $ this-> renderpartial ('show ', array ('goods _ Infos '=> $ Infos); // The save () method executes update or insert // $ model-> Save ();}
Yii Data Query and class library tracking