I had to save Japanese characters in a CSV file to a mySQL table and then display those characters on another page.
- I created a table in mySQL and converted the table collation and character set to utf8. I use community version of sqlyog as a mySQL client. You can change the collation and character set very easily as can be seen in the snap shot.
You can also do this using the SQL CREATE and ALTER statements as well. It depends on which ever method you are comfortable with.
- Next I updated the PHP code and added the statement SET NAMES utf8 just after opening the connection to the mySQL database so mySQL knows that there will be data which will be in unicode format and it will need to be handled accordingly.
You don’t need to run this statement if you are using any professional MVC framework as they cater to an international audience.
- After doing steps 1 and 2 I wrote the script which read the CSV file and inserted the data into the database table and the data was saved successfully.
Hope the above helped you all.
Please follow and like us: