I’m getting encoding problem when I insert names in a mySQL table, that contains special characters, like “ö”, “ä” etc.
For example, the word “Öl” becomes “öl”.
I’ve tried to write the names to a text file and then they show up properly.
I’ve tried to insert the names in phpMyAdmin using SQL-statements, and that works good as well.
Now I found a solution in setting mysql_query('SET NAMES utf8;'); before the insert query.
Is this how it should be done, or is there a better way?
yeah running the SET NAMES utf8; is needed to make the MySQL know that the client connection is using ut8 while sending the data. You can though now define it inside the PDO connection (if you are using PDO for connecting to the MySQL).
If running PHP version older than 5.3.6 then you can use the following code:
else use the following: