I am trying to write a condition into a SQL WHERE clause that forces the column comparison to a variable to be compared in lowercase. However the addExpression function isn't accomplishing this (since that is putting the expression in the field selection, not the where clause.
Here is what I have tried:
$category = 'mobile wifi';
$query = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'));
$query->innerJoin('taxonomy_vocabulary', 'tv', 'ttd.vid = tv.vid');
$query->addExpression("LOWER(ttd.name) = $category");
$result = $query->condition('machine_name', 'images_cat', '=')
->execute()
->fetchAssoc();
And this:
$category = 'mobile wifi';
$query = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'));
$query->innerJoin('taxonomy_vocabulary', 'tv', 'ttd.vid = tv.vid');
$result = $query->condition('machine_name', 'images_cat', '=')
->condition('LOWER(ttd.name)', $category, '=')
->execute()
->fetchAssoc();
The second one becomes invalid and the first one causes the problem I mentioned above. Any thoughts or suggestions?
Thanks, Patrick