Yii Data Query and class library tracking

Source: Internet
Author: User

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

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.