php - MySQL "LIKE" search doesn't work -
i've imported .txt database in mysql through "load data infile", , seemed working, problem if search record on db following query:
"select * hobby name 'beading'"
it returns 0 rows, while if use
""select * hobby name '%beading%'"
it returns 1 row, if exist 1 record name=beading. know depend on?
when using sql like
:
you should use wildcard identifier such (or not):
'%word'
- return results value ends letters: "word".'word%'
- reurn results begin letters: "word".%word%
- return results include letters: "word" anywhere.there more pattern search combination like:
'abc' 'abc' true
'abc' 'a%' true
'abc' 'b' true
'abc' 'c' false
if want exact match should use:
"select * hobby name='beading'"
but like 'beading'
should work also, spaces issue or case sensitivity porblem.
you need take care of collation case (sensitivity) when want make sure results complete.
say table utf...cs , want make insensitive case search should declare in sql query, example:
select * hobby name collate utf8_general_ci 'beading'
try testing different approaches , see fits goal best.
Comments
Post a Comment