I have a database that stores data as UTF-8, but sometimes some data (outside of my control) is added with unrecognized characters which are stored as question marks (?). Is there any way to configure MySQL to remove those characters instead?
I have a database that stores data as UTF-8, but sometimes some data (outside
Share
maybe solving the problem instead of working around it will be the better solution. if you just remove the question marks, the stored data wouldn’t be so ugly as it#s now, but it will still be wrong (wrong = not exactly the data the user wanted to save).
this problem sounds like you’ve missed to specify a character encoding somewhere, so that the client’s default settings are used (you havn’t said wich exactly are the clients – maybe the users browser?) wich seems to be utf-8 or something compatible most times – but sometimes there’s a clint with an exotic default charset wich makes you run into problems.
to solve this, simply make sure you’ve set character encoding to utf-8 everywere:
tell MySQL to use utf-8. to do this, add this to your my.cnf:
before interacting with mysql, send this two querys:
or, alternatively, let php do this afteropening the connection:
set UTF-8 as the default charset for your database
do the same for tables:
assuming the client is a browser, serve your content as utf-8 and the the correct header:
to be really sure the browser understands, add a meta-tag:
and, last but not least, tell the browser to submit forms using utf-8