Mysql turns ' into ’?

后端 未结 3 726
我在风中等你
我在风中等你 2021-01-02 00:31

How can I stop mysql from converting \' into ’ when I do an insert?

i believe it has something to do with charset or something?

3条回答
  •  余生分开走
    2021-01-02 01:20

    Maybe someone will know the answer immediately, but I don't. However here are a few suggestions on what to examine (and possibly expand the question on)

    When dealing with encodings and escaping you should include the full history of data

    • how was it created
    • what happened to it before the problem (did it have to go through backup, e-mail, was it created on a different server, OS, etc..; if it was transferred then was it as text file?)

    The above is because anything that writes to a text file (browser, mysql client, web server, php application, to name a few layers that could have done it) can mess up character coding.

    To troubleshoot, you can start eliminating, and thus the first step (in my book), is to

    1. connect to mysql server using mysql command line client.
    2. check the output of SHOW VARIABLES LIKE 'character_set%'
      (so even in this simple environment you have 7 values that can influence how the data is parsed, stored and/or displayed
    3. inspect SHOW CREATE TABLE TableName, and look for charset and collation info, both default for the table and explicit definition on columns

    Having said all of the above, I don't think any western script would transcode a single quote character. So you might need to look at your escaping and other data processing.

    EDIT Most of the above from answer and discussion here

提交回复
热议问题