I am trying to query a column with createCommand doing something like this:
Yii::$app->db->createCommand('Select column1 from table where column2 in :array)
->bindValues(['array'=>['(1,2,3,4,5)', PDO::PARAM_INT]])->queryColumn('COLUMN1');
Ideally I want my SQL statement to be executed like
select column1 from table where column2 in (1,2,3,4,5)
However when the SQL executes there is always quotes wrapped around the binded parameters like so:
select column1 from table where column2 in '(1,2,3,4,5)'
I'm not sure why this is still happening after I specify the PDO to use PDO::PARAM_INT. Isn't int supposed to not be quoted?
You could try a slightly different approach using Query Builder:
This has the desired effect: the where clause is automatically generated using the in (...) syntax because of the array passed in.
Not sure if you explicitly need to cast the types of the array to INT if they happen to be of type STRING internally in PHP though...