IN query IN Yii framework parameterized query can only query one solution. yii framework
This example describes how to query only one IN query IN parameter query of Yii framework. We will share this with you for your reference. The details are as follows:
IN the yii framework, when parameterization is used for IN queries, the results are not as expected.
$sql =<<<SQLSELECT id FROM tb WHERE id IN(:ids)SQL;$db = GeneralService::getSlaveDB();$result = $db->createCommand($sql)->query([':ids' => '1013,1015,1017'])->readAll();print_r($result);
Array( [0] => Array ( [id] => 1013 ))
So I searched the source code in the yii framework and found that pdo queries were used, so I found the pdo related information and found the cause:A placeholder cannot replace a group of values..
SELECT id FROM tb WHERE userid IN ( ? );
Now that you know the reason, find the alternative method. FIND_IN_SET can meet
$sql =<<<SQLSELECT id FROM tb WHERE FIND_IN_SET(id, :ids)SQL;$db = GeneralService::getSlaveDB();$result = $db->createCommand($sql)->query([':ids' => '1013,1015,1017'])->readAll();print_r($result);
Array( [0] => Array ( [id] => 1013 ) [1] => Array ( [id] => 1015 ) [2] => Array ( [id] => 1017 ))
FIND_IN_SET function in simple science
FIND_IN_SET(str,strlist)
If the str string is in the strlist consisting of N substrings, the return value ranges from 1 to N.
A string list is a string consisting of substrings separated by commas. If the first parameter is a constant string and the second parameter is the type SET column, the FIND_IN_SET () function is optimized and computed in bits.
If str is not in strlist or strlist is a null string, the return value is 0. If any parameter is NULL, the return value is NULL. This function cannot run normally when the first parameter contains a comma.
[Ps] strlist is a string consisting of commas (,). It cannot be recognized because a space is added to the right of a comma as it is normally used.