user1867350
user1867350

Reputation: 41

†characters in mysql database

Storing some values in a mysql database, the input is being sanitized with mysql_real_escape_string($value) and it displays fine. However while performing a direct query on the database, I'm seeing characters like †on each text field that has been edited using this form. How does that happen? It doesn't show when I display values on webpages but how can I prevent these characters from appearing at all?

I looked at this question: Strange characters in mysql dbase which seemed to have some advice on setting character names on the input, but how can I fix this for once and for all? I believe the person who's updating these values is copying and pasting directly from Microsoft Word, so I'm sure it has something to do with the "smart quotes" and other such fancy formatting that MS Word likes to use.

Upvotes: 1

Views: 1136

Answers (1)

Armage
Armage

Reputation: 677

As the answer you linked shows, it comes from PHP which connects to mysql with latin1 encoding by default. So the datas are not correctly inserted in database. Another problem is that if you query back the data in php, you get correct data as they are "decoded" the same way they are encoded. But if you perform direct query in database (say, with mysql client on console), data seem broken.

That's why the answer is to query "SET NAMES UTF8" before anything else. You may parameter the mysql server to force utf8 on any connection. I do not see any other solution.

Upvotes: 1

Related Questions