I have come across some problems when inputting certain characters into my mysql database using php. What I am doing is submitting user inputted text to a database. I cannot figure out what I need to change to allow any kind of character to be put into the database and printed back out through php as it’s suppose to.
My MySQL collation is: latin1_swedish_ci
Just before I send the text to the database from my form I use mysql_real_escape_string() on the data.
Example below
this text:
�People are just as happy as they make up their minds to be.�
� Abraham Lincoln
is suppose to look like this:
“People are just as happy as they make up their minds to be.”
― Abraham Lincoln
As mentioned by others, you need to convert to UTF8 from end to end if you want to support “special” characters. This means your web page, PHP, mysql connection and mysql table. The web page is fairly simple, just use the meta tag for UTF8. Ideally your headers would say UTF8 also.
Set your PHP to use UTF8. Things would probably work anyway, but it’s a good measure to do this:
For mysql, you want to convert your table to UTF8, no need to export/import.
You can, and should, configure mysql to default utf8. But you can also run the query:
as the first query after establishing a connection and that will “convert” your database connection to UTF8.
That should solve all your character display problems.