Yii2:更新字段错误未知列与查询生成器

时间:2016-04-17 15:20:17

标签: mysql pyyaml

我有数据库表'cat_ralation'

CREATE TABLE IF NOT EXISTS `cat_relation` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`cat_id` int(11) NOT NULL,
`obj_id` int(11) NOT NULL,
`obj_type` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

插入数据

id = 1,
cat_id = 2,
obj_id = 3,
obj_type = product

Qyery建设者

Yii::$app->db
   ->createCommand()
   ->update('cat_relation',['cat_id'=>3], 'obj_id = 3 AND obj_type = product')
   ->execute();  

错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product' in 'where clause'
The SQL being executed was: UPDATE `cat_relation` SET `cat_id`=2 WHERE obj_id = 4 AND obj_type = product

1 个答案:

答案 0 :(得分:0)

使其像

Yii::$app->db
   ->createCommand()
   ->update('cat_relation',['cat_id'=>3], "obj_id = 3 AND obj_type = 'product'")
   ->execute();