I'm trying to construct a fairly simple LIKE query using the Query Builder, and I'm struggling. Here's the SQL that I want:
SELECT `id` FROM `craft_somecustomtable` WHERE ((`somecolumn` LIKE '%foo%') OR (`somecolumn` LIKE '%bar%'))
I've ran the above query in Sequel, with results.
For the Query Builder, here's what I've got so far:
$query = craft()->db->createCommand();
$query->select('id');
$query->from('somecustomtable');
$query->orWhere(array(
'somecolumn' => 'LIKE %foo%',
));
$query->orWhere(array(
'somecolumn' => 'LIKE %bar%',
));
This produces the following query, which obviously doesn't work as intended:
SELECT `id` FROM `craft_somecustomtable` WHERE ((`somecolumn`='LIKE %foo%') OR (`somecolumn`='LIKE %bar%'))
I've also tried adding the LIKE
directive like this:
$query->orWhere(array(
'somecolumn LIKE' => '%bar%',
));
This produces an error, however.