UTF-8 problem when saving to mysql

前端 未结 5 1460
轮回少年
轮回少年 2020-12-12 02:36

My website is using charset iso 8859 1


when user post

5条回答
  •  独厮守ぢ
    2020-12-12 03:07

    You should follow ajreal's advice on setting your encodings to UTF-8.

    However, from the sound of it you may already have data stored in the database which will have to be converted.

    If your website is uniformly iso-8859-1 then most likely Chinese characters are stored as HTML character entities, which means that data is not not stored mis-encoded and converting the character sets should not cause problems. If you carry out the instructions and find that characters appear incorrectly afterwards, it might be because text is stored mis-encoded, in which case there are steps that can be taken to remedy the situation.

    Character sets for an existing column may be converted using syntax like

    ALTER TABLE TableName MODIFY ColumnName COLUMN_TYPE CHARACTER SET utf8 [NOT NULL]
    

    where COLUMN_TYPE is one of CHAR(n), VARCHAR(n), TEXT and the square brackets indicate that NOT NULL is optional.

    Edit

    "my question is, after i set to UTF-8, how to i make mysql save the text as # 2 0 3 2 0 ; & # 2 2 9 0 9 ; instead of funky chars."

    This might be best tackled in your scripting language rather than in MySQL. If using PHP you might be able to use htmlentities() for this purpose.

提交回复
热议问题