Search code examples
phpmysqlunicodeunicode-escapesncr

How to search the MySQL entries shown as decimal numeric character reference(NCR) &#xxxxx?


When I am searching my MySQL database with some query like:

SELECT * FROM mytable WHERE mytable.title LIKE '%副教授%';

("副教授" are three Chinese characters, whose decimal numeric character reference, NCR, is "副教授"), I got no result.

By looking into the phpMyadmin and browsing "mytable", the should-be-found entry is shown as "副教授". I think that is the reason for the failure of search.

Not all the entries in the same column are numeric character reference and some of them are just normal. Here is one pic of the table column shown in phpMySQLAdmin.

enter image description here

I wonder how I could search for all entries in my table in MySQL using one format regardless if there are shown in NCR or not. Or should I convert the NCR entries by running some script? Thanks.


Solution

  • your database table encoding should be utf-8 and when you insert new data you should run set names 'utf-8' query before insertion and this will contain all your data.