Yii database query method_php instance

Source: Internet
Author: User
This article mainly introduces the yii database query method, and analyzes the techniques for directly querying and using criteria in combination with instances, for more information about how to query yii databases, see the following example. We will share this with you for your reference. The details are as follows:

Two query methods are described here. One is direct query, and the other is to use criteria for query.

The Code is as follows:

$ User = User: model ();

1. Direct query:

$ Arr = array ("select" => "username, password, email", // the field to be queried "condition" => "username like '% 6 '", // query condition "order" => "id desc", "limit" => 5, "offset" => 1 ,); $ info = $ user-> findAll ($ arr );

2. Use criteria:

$ Criteria = new CDbCriteria (); $ criteria-> select = "username, password, email"; $ criteria-> condition = "username like '% 1 '"; $ criteria-> limit = 5; $ criteria-> order = "id desc"; $ criteria-> offset = 1; $ info = $ user-> findAll ($ criteria );

I hope this article will help you design PHP programs based on the yii framework.

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.