Table of Contents
Yii2.0 Chinese Development Guide - Full analysis of Where condition query,
Home Backend Development PHP Tutorial Yii2.0 Chinese Development Guide - Full analysis of Where condition query, _PHP tutorial

Yii2.0 Chinese Development Guide - Full analysis of Where condition query, _PHP tutorial

Jul 13, 2016 am 09:44 AM
where Chinese develop condition Inquire parse

Yii2.0 Chinese Development Guide - Full analysis of Where condition query,

Where is essential when querying in Yii Model.
Where method is declared as


The parameter $condition type is string or array

1. String
String is the simplest. Just write it directly according to the where condition in sql, such as

2. Array
If it is an array, there are two ways to write it.

  • Dictionary array in name-value format: ['column1' => value1, 'column2' => value2, ...]
  • Logical operator format: [operator, operand1, operand2, ...]

First way of writing:
If value is a string or number, etc., then the generated conditional statement format is column1=value1 AND column2=value2 AND ....

['type' => 1, 'status' => 2]

//Generate

(type = 1) AND (status = 2)


If value is an array, then the IN ​​statement in sql will be generated;

['id' => [1, 2, 3], 'status' => 2]

//Generate

(id IN (1, 2, 3)) AND (status = 2)

If value is Null, then the Is Null statement will be generated.

['status' => null]

//Generate

status IS NULL

The second way of writing will generate different sql conditions based on different operators.

    • and: will use AND to connect all operands. like

      ['and', 'id=1', 'id=2']

      // Generate

      id=1 AND id=2

      If an operand is also an array, it will be converted to a string in the following format, such as

      ['and', 'type=1', ['or', 'id=1', 'id=2']]

      //Generate

      type=1 AND (id=1 OR id=2)

      Note: This method does not reference or encode the value.
    • or: is similar to and, except that OR is used to connect the operands.
    • between: The first operand is the name of the column, the second and third operands are the minimum and maximum values ​​of the range. like

      ['between', 'id', 1, 10]

      //Generate

      id BETWEEN 1 AND 10

    • not between: is similar to between.
    • in: The first operand is a column or DB expression, and the second operand is an array, such as

      ['in', 'id', [1, 2, 3]]

      //Generate

      id IN (1, 2, 3)

      Note: This method will reference the column and also encode the values ​​in the array.
    • not in: is similar to in above.
    • like: The first operand is a column or DB expression, and the second operand is a string or array, such as

      ['like', 'name', 'tester']

      //Generate

      name LIKE '%tester%'

      If the value is an array, multiple like statements will be generated and connected using AND. like

      ['like', 'name', ['test', 'sample']]

      //Generate

      name LIKE '%test%' AND name LIKE '%sample%'

      Note: This method will reference the column and also encode the values ​​in the array.
      Sometimes you may need to handle % yourself, then you can use the third parameter:

      ['like', 'name', '%tester', false]

      //Generate

      name LIKE '%tester'

    • or like: is similar to like, except that or is used to connect multiple like statements when the second parameter is an array.
    • not like: is similar to like.
    • or not like: is similar to or like.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1043455.htmlTechArticleYii2.0 Chinese Development Guide - Full analysis of Where condition query, when querying where in Yii Model is essential. Where method is declared as where parameter $condition type is word...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set Chinese in Call of Duty: Warzone mobile game How to set Chinese in Call of Duty: Warzone mobile game Mar 22, 2024 am 08:41 AM

Call of Duty Warzone is a newly launched mobile game. Many players are very curious about how to set the language of this game to Chinese. In fact, it is very simple. Players only need to download the Chinese language pack, and then You can modify it after using it. The detailed content can be learned in this Chinese setting method introduction. Let us take a look together. How to set the Chinese language for the mobile game Call of Duty: Warzone 1. First enter the game and click the settings icon in the upper right corner of the interface. 2. In the menu bar that appears, find the [Download] option and click it. 3. Select [SIMPLIFIEDCHINESE] (Simplified Chinese) on this page to download the Simplified Chinese installation package. 4. Return to the settings

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

See all articles