Home Backend Development PHP Tutorial Solve the problem that IN query in Yii framework parameterized query can only query one

Solve the problem that IN query in Yii framework parameterized query can only query one

Jan 03, 2018 pm 01:19 PM
parameter Inquire frame

How to solve the problem that only one IN query can be queried in the Yii framework parameterized query? This article mainly introduces the solution to the problem that only one IN query can be queried in the Yii framework parameterized query, and analyzes the IN query in the Yii framework in the form of examples. The reason why you can only check one function and the related functions and usage skills of the FIND_IN_SET function can be referenced by friends who need it. I hope to be helpful.

The details are as follows:

When using parameterization for IN query in the yii framework, the results were not as expected

$sql =<<<SQL
SELECT id FROM tb WHERE id IN(:ids)
SQL;
$db = GeneralService::getSlaveDB();
$result = $db->createCommand($sql)->query([&#39;:ids&#39; => &#39;1013,1015,1017&#39;])->readAll();
print_r($result);
Copy after login
Array
(
  [0] => Array
    (
      [id] => 1013
    )
)
Copy after login

So I checked the relevant source code in the yii framework and found that the It was a pdo query, so I queried pdo related information and found out the reason: cannot let placeholders replace a set of values ​​.

SELECT id FROM tb WHERE userid IN ( ? );
Copy after login

Now that you know the reason, then find an alternative method. FIND_IN_SET can just meet the requirements

$sql =<<<SQL
SELECT id FROM tb WHERE FIND_IN_SET(id, :ids)
SQL;
$db = GeneralService::getSlaveDB();
$result = $db->createCommand($sql)->query([&#39;:ids&#39; => &#39;1013,1015,1017&#39;])->readAll();
print_r($result);
Copy after login
Array
(
  [0] => Array
    (
      [id] => 1013
    )
  [1] => Array
    (
      [id] => 1015
    )
  [2] => Array
    (
      [id] => 1017
    )
)
Copy after login

FIND_IN_SET function under simple popular science

FIND_IN_SET(str,strlist)
Copy after login

If the string str is composed of N sub In the string list strlist composed of chains, the return value ranges from 1 to N.

A string list is a string consisting of subchains separated by ',' symbols. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit calculations.

If str is not in strlist or strlist is an empty string, the return value is 0. If any parameter is NULL, the return value is NULL. This function will not work properly if the first argument contains a comma (',').

[ps] The string consisting of commas in strlist cannot be recognized by adding a space to the right of the comma as usual.

Related recommendations:

Detailed explanation of restful api authorization verification of yii2

Detailed explanation of how Yii2 implements a custom independent validator

##Yii2 integrates Xunsou to achieve efficient Chinese word segmentation retrieval

The above is the detailed content of Solve the problem that IN query in Yii framework parameterized query can only query one. For more information, please follow other related articles on the PHP Chinese website!

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

vivox200ultra parameters and price details vivox200ultra parameters and price details Jun 28, 2024 pm 01:23 PM

The latest official news of vivox200ultra has exposed the parameters and price details of vivox200ultra. It is reported that vivox200ultra will be equipped with a 10x periscope super telephoto lens, and the price starts at about 6999 yuan. It can be seen that it occupies an absolute advantage in photography performance. The following are the parameters and prices of vivox200ultra Come and see the details. 1. Parameter configuration details of vivox200ultra 1. Vivox200ultra rendering From the vivo X200 Ultra rendering, the front of the phone adopts a borderless full-screen design, and the visual effect of the entire front of the phone can be said to be very invincible. 2. vivox200ultra has Blackhawk frame

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

Performance comparison of Java frameworks Performance comparison of Java frameworks Jun 04, 2024 pm 03:56 PM

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

Golang framework documentation best practices Golang framework documentation best practices Jun 04, 2024 pm 05:00 PM

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Java Framework Learning Roadmap: Best Practices in Different Domains Java Framework Learning Roadmap: Best Practices in Different Domains Jun 05, 2024 pm 08:53 PM

Java framework learning roadmap for different fields: Web development: SpringBoot and PlayFramework. Persistence layer: Hibernate and JPA. Server-side reactive programming: ReactorCore and SpringWebFlux. Real-time computing: ApacheStorm and ApacheSpark. Cloud Computing: AWS SDK for Java and Google Cloud Java.

See all articles