-1

I have database table '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;

insert data

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

Qyery builder

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

error

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
luongit
  • 117
  • 2
  • 13

1 Answers1

0

make it like

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