Yii框架中如何绑定数组参数?

2022-01-04 00:00:00 php yii yii1.x

我有以下代码:

$inputs = "1,2,3,4,5";
$sql = "SELECT * FROM obj WHERE id IN(:input)";

$commond = Yii::app()->db->createCommand($sql);
$commond->bindValue(":input", $inputs , PDO::PARAM_STR);

但是查询结果不正确.如何为这种 IN 条件绑定参数?

But the query result is incorrect. How to bind params for such IN condition?

推荐答案

现在就这样使用

$command = Yii::app()->db->createCommand()
    ->select()
    ->from('tableName')
    ->where(array('in', 'id', explode(',', $inputs)));

我将尝试使用 $command->bindValue() 方法返回.

I ll try to get back with $command->bindValue() method.

相关文章