Can't get the encoding right in MySQL

前端 未结 2 1785
慢半拍i
慢半拍i 2021-01-22 12:51

I have been struggling with encoding problems in MySQL for a while. I am building a database that will contain not only Latin but Cyrillic and Arabic text as well. So here is an

相关标签:
2条回答
  • 2021-01-22 13:10

    Whatever happens to your characters, happens before they reach to MySQL, I guess. Characters are converted to numbers by the computer when we enter the characters. Then these numbers travel from here to there, between web forms and servers, web servers and scripting interpreters, then database servers and back to web pages following the same way.

    Where and how you enter your data? Data should exit the way it entered. If your data is provided via web forms, check your web page encodings and how you submit forms. How you get them in your PHP scripts and how you send them to database server. The guilty part here is probably not MySQL but another place. It can be MySQL too; but it is not the only place of possible misbehavior and it probably is not.

    Check your pages, check headers as they arrive to your browser.

    About comments your question received, no it is not good to use ISO5 because you need multiple of ISO5 families. You must go with a Unicode encoding, for most of the time, the best being utf-8. Also, this is not about which MySQL library you use unless that library has some known bugs which is very unlikely for something that old. :) You should still use whatever recommended as best practices; but your current problem is not related to the library you use. The evil is at the difference between how you enter your data and how you view it.

    0 讨论(0)
  • 2021-01-22 13:28

    ensure that you have this meta in your page's header

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
    

    Also you could try executing this query right after connecting to the db :

    "SET NAMES 'utf8'"
    

    Hope this helps. Cheers

    0 讨论(0)
提交回复
热议问题