I'd also like to know what the actual string value of $countsql is, and like Michael said, whether the query is being rewritten by another module.
The other option appears to be to change the collation of the table(s) in question. According to this:
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
certain collations are automatically case insensitive. I had initially hesitated to make such a change to the schema, but it appears to be an option if my current approach fails.
Fred