【发布时间】:2015-11-18 16:29:00
【问题描述】:
当我在 Yii2 中使用 bindParam 时:
$arr = [1,3];
$str = implode(' ,', $arr);
Yii::$app->db->createCommand('DELETE FROM article_tag WHERE article_id=:id AND tag_id IN (:str)')
->bindValue(':id', $this->id)
->bindValue(':str', $str)
->execute();
如果我将 str 绑定到 IN 字段,原始 sql 似乎变成了
SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '1 ,3'
The SQL being executed was: DELETE FROM article_tag WHERE article_id=13 AND tag_id IN ('1 ,3')
它告诉我这里的双精度值不正确。我猜这是因为它在 sql 中添加了单引号。我该如何处理??
【问题讨论】: