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