Searching for mySQL data in case insensitive mode

I’ve been working on search engine on one of the sites and everything worked just fine until I found this rather strange bug, where my content wouldn’t show up in search results, even if my target article clearly had the searched term (‘discounts’) in its title (I had 4 objects with the same ‘Crazy Discounts now’).

I was using rather classic search method, like this:

AND (md.name LIKE '%{$kw}%' 
OR pd.name LIKE '%{$kw}%' 
OR pd.short LIKE '%{$kw}%'

And 3 out of 4 queries worked just fine, but one didn’t. So I tried searching for ‘Discounts’ (capitalized) and suddenly got all 4 results.

So I tried casting my search term and table column names to lowercase and comparing that, but that didn’t work too. After a bit of testing I’ve found out that the nonworking query actually returned blob as the result (pd.name column), which is case sensitive, opposite of text, varchar and char data types. So all I did then was to cast blob type as regular string and suddenly everything worked:

AND (md.name LIKE '%{$kw}%' 
OR CONVERT(pd.name USING utf8) LIKE '%{$kw}%' 
OR pd.short LIKE '%{$kw}%'

Notice the CONVERT command on pd.name column.