MySQL hyphen in LIKE expression
I am working with a legacy PHP framework and am coming across some strange behavior that I can't track down.
I'm running a query that looks something like this
select * from table开发者_如何学编程 where column like '%word-anotherword%'
, which I would like to return records from table where column contains the text "word-anotherword". (column is a longtext field).
When I run this query in phpMyAdmin, I get the expected results. But when I run it from inside our framework, I get no results. I have run it in a separate .php file, using mysql_link
, mysql_query
to run the query, and that also behaves as expected.
When I echo
out the query in the framework directly before it is passed to mysql_query
, it is formatted just the same as I expect. I.E. our framework is not escaping it in some unexpected manner.
I am assuming that our framework is overriding some PHP setting somewhere to cause this difference in behavior, but I have had no luck googling for what it might be. I found this article, which seemed to be a good start, but also didn't quite seem to fit what I'm seeing, since I am getting different behaviors on the same MySQL setup.
Any pointers in the right direction would be greatly appreciated!
As a debugging heads-up:
When you echo
your query out, you might want to make sure you're actually seeing the data - e.g. if you're echo
-ing onto a webpage, make sure you're applying htmlspecialchars()
to the string. Otherwise you might not spot some changes.
LIKE is not full text search, that's why question title is wrong and, probably, that article which you found isn't related to your problem.
And about your problem, open your my.cnf and enable queries log:
[mysqld]
#Set General Log
log = "C:/all_queries.log"
Now run your query and look into log.
精彩评论