Input UTF8 data conveniently to MySQL

2019-06-04 07:46发布

I'm from Hungary which makes things complicated if talking about character encoding. When I code websites I cannot avoid storing simple data in MySQL which normally would not require an admin surface to handle. I mean I would not make an admin for recording menu names in a table. But I have to. Since it's impossible (or I haven't found a solution yet) to record UTF8 attributes in phpMyadmin. My input stays ISO-8859-2 encoded in the UTF8 field as I send it via phpMyadmin. If I send data to the database using an UTF8 webpage, UTF8 form, everything UTF, I have absolutely no problem.

So my point is that it's circumstantial and time-consuming to make an admin surface or something like that every time I want to insert some UTF8 to an UTF8 encoded database. phpmyadmin is unusable for me. But I don't feel like programming another phpmyadmin on my own. It would make no sense. There must be a solution. Can you help?

Actual UTF8 attributes show off the right way. The line marked with blue line has been recorded with phpmyadmin and is not stored as UTF8.

(Actual UTF8 attributes show off the right way. The line marked with blue line has been recorded with phpmyadmin and is not stored as UTF8.)

3条回答
Juvenile、少年°
2楼-- · 2019-06-04 08:02

For those who might find this article in the future with the same problem, I've set the connection encoding right after setting up the connection using this query:

SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'

查看更多
看我几分像从前
3楼-- · 2019-06-04 08:17

I had exactly the same problem as you. After a while, I figure out the solution, using a utf8-to-html online converter at Convert to HTML . Just type your Unicode text and copy the result, paste into your PHPMyadmin.

查看更多
Luminary・发光体
4楼-- · 2019-06-04 08:20

I'll just take a very wild stab into the dark:

phpMyAdmin actually gets it right. The one that isn't working is your custom interface, because it's not setting the connection encoding correctly. So all the data you insert via it is messed up in the database but happens to have a clean roundtrip in your application. phpMyAdmin inserts actual UTF-8 data, which messes up when retrieved via your wrong connection.

See UTF-8 all the way through and Handling Unicode Front To Back In A Web App.

查看更多
登录 后发表回答