A detailed description of where parameter query for Yii2 addition, deletion, modification, and query, yii2where

Source: Internet
Author: User

A detailed description of where parameter query for Yii2 addition, deletion, modification, and query, yii2where

Overview

Since there are few introductions to where in the official manual, I 'd like to sort it out by myself so that you can learn and look back at it. This article describes how to use and, or, between, in, and like in The where method and provides examples.

And

// We Want to query the data whose id is greater than 1 and less than 3 $ userInfo = User: find ()-> where (['and', 'Id> 1 ', 'id <3'])-> all (); // or use the following method to make it safer: $ userInfo = User: find ()-> where (['and ', ['>', 'id', 1], ['<', 'id', 3])-> all (); // We often process SQL statements that are more complex than this. // if we want to query data whose name is Wang Wu and whose id is greater than 1 or whose id is less than 3, $ userInfo = User: find () -> where (['and', ['=', 'name', 'wang 5'], ['or', ['=', 'id', 1], ['=', 'id', 3])-> asArray ()-> all (); // Note: asArray () the data is displayed as an array.

Or

// We Want to query data whose id is equal to 1 or whose id is equal to 3 $ userInfo = User: find ()-> where (['or', 'Id = 1 ', 'id = 3'])-> all (); // we can also use the following method $ userInfo = User: find ()-> where (['or ', ['=', 'id', 1], ['=', 'id', 3])-> all (); // What if we want to query IDs in the range of 4, 8, 9, or IDs in the range of 1, 2, and 3? $ UserInfo = User: find ()-> where (['or', ['id' => [, 9], ['id' =>, 3])-> all ();

Between

// We Want to query the range of IDs from 1 to 10 $ userInfo = User: find ()-> where (['between', 'id', 1, 10]) -> all ();

In

// We Want to query $ userInfo = User: find ()-> where (['in', 'id, 3])-> all ();

Like

// We Want to query the data whose name contains the "Zhang" character $ userInfo = User: find ()-> where (['like', 'name ', 'zhang'])-> all (); // assume that the wildcard name contains the "Zhang" character and must contain the "3" character $ userInfo = User :: find ()-> where (['like', 'name', ['zhang', '3'])-> all (); // assume that you only need to configure $ userInfo = User: find ()-> where (['like', 'name', '% 3', false]) on the left. -> all (); // so, the same is true on the right.

The above section describes how to query the where parameter in Yii2, add, delete, modify, and query. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.