Reputation: 4610
How build this query with YIi query builder
SELECT *
FROM `table`
WHERE type_item = 2 AND name_item LIke '%name%'
I tried so
return Yii::app()->db->createCommand()
->select('*')
->from('{{event_field_variants}}')
->where('type_item = :type AND name_item LIKE "%:substr%"', array(':type' => '2', ':substr' => 'name'))
->order('variant ASC')
->queryAll();
But this query get CdbcException. On Yii documentation are examples only with like or only with simple param.
Upvotes: 2
Views: 8113
Reputation: 29985
->where('name_item LIKE :substr', array(':substr' => '%name%'))
Just put it in the variables part?
Upvotes: 10