Solve the query in the YII framework parameterized query only one problem

Source: Internet
Author: User
Tags yii
How to solve the in query in the YII framework parameterized query can only query one of the problems? This paper mainly introduces the solution to query in query of Yii frame parameterized query, and analyzes the reason and find_in_ of the in query only one in the Yii frame by the example form. Set function related functions and the use of skills, the need for friends can refer to. We hope to help you.

Specific as follows:

When using parameterized in queries in the YII framework, the results are not as good as you would like

$sql =<<<sqlselect ID from TB WHERE ID in (: IDS) sql; $db = Generalservice::getslavedb (); $result = $db->createco Mmand ($sql)->query ([': ids ' = ' 1013,1015,1017 '])->readall ();p rint_r ($result);
Array (  [0] = = Array    (      [id] = 1013    ))

Then turned on the YII framework of the relevant source code, found that the use of PDO query, and then query the PDO related data, know the reason: the placeholder can not be replaced by a set of values .

SELECT ID from the TB WHERE userid in (?);

Now that you know the reason, then find the alternative, Find_in_set just can meet

$sql =<<<sqlselect ID from TB WHERE find_in_set (ID,: IDS) sql; $db = Generalservice::getslavedb (); $result = $db-&G T;createcommand ($sql)->query ([': ids ' = ' 1013,1015,1017 '])->readall ();p rint_r ($result);
Array ([  0] = = Array    (      [id] = 1013    )  [1] = = Array    (      [id] = 1015    )  [2] = = Array    (      [id] = 1017    ))

Find_in_set function under simple Popular science

Find_in_set (Str,strlist)

If the string str is in a string list strlist consisting of N substrings, the return value ranges from 1 to N.

A string list is a string of sub-chains that are separated by ', ' symbols. If the first argument is a constant string and the second is a type set column, the Find_in_set () function is optimized to use bit calculations.

If STR is not strlist or strlist is an empty string, the return value is 0. If either parameter is NULL, the return value is null. This function will not work correctly when the first parameter contains a comma (', ').

"PS" strlist in a comma-composed string, not as usual, the comma to the right of a space, it is not recognized.

Related recommendations:

Detailed YII2 's RESTful API authorization verification

Detailed YII2 how to implement a custom standalone validator

YII2 integrated Fast Search for efficient Chinese word search

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.