Error in Arabic script in MySQL

此生再无相见时 提交于 2019-12-23 04:51:41

问题


I inserted data in a MySQL database which includes Arabic script. While the output displays Arabic correctly, the data in MySQL looks like garbage. Something like this:

 'صَومُ ثَلاثَةِ أيّامٍ مِن كُلِّ شَهرٍ ـ أربَعاءُ بَينَ خَ

Should I be worried about this? If yes, how do I make it appear in proper Arabic script in MySQL?


回答1:


Those are HTML entities.

If this text

صَومُ ثَلاثَةِ أيّامٍ مِن كُلِّ شَهرٍ ـ أربَعاءُ بَينَ خَ

is what is supposed to be in your database, everything's most likely fine: Your arabic input gets converted into those entities at some point along the way.

To view the actual arabic characters like above, insert them into a text file, name it something.htm and open it in your browser.

You could also convert it into "proper" native characters in a UTF-8 encoded mySQL table, but for you to get any pointers how to do that you would have to tell us what languages/platforms you are working with.




回答2:


As @Pekka says, those are HTML entities.

However, I can't help but think using UTF-8 (for both the database connection and HTML encoding) might save you some pain in the long run. Likewise, if at all possible (i.e.: if this is a "new" system rather than an existing codebase) I'd recommend storing the data raw in the database (using mysql_real_escape_string to prevent SQL injection, etc.) and HTML encoding at the point of output.

In general, this will make it easier to search the data, etc.



来源:https://stackoverflow.com/questions/2595915/error-in-arabic-script-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!