Import Chinese into Database without garbles

Some detail when importing Chinese from CSV file into database via PHP script

Hello everyone. It’s Ray!
Today I am going to share more details of importing Chinese characters into database from CSV file via PHP script

Firstly, let’s start from PHP script

<?php
mysqli_set_charset($dbc,"utf8");

After the code of connecting to database, bear in mind that the code above should be added in order to specify the default format of data from and to database.

As to CSV file:

Firstly, open it with Excel, open new

Secondly, choose data, and click from text

Use delimiter

Use comma to delimit the data

Finally, general is fine.

As to database:

If you use GUI tool such as Sequel Pro, remember to choose UTT-8 when creating a new table

If you use terminal, as image below, remember to specify the utf8 format when creating a new table

If garble still occurs, check if the format for each column is utf-8

Basically, if all above mentioned is followed, you should be able to import Chinese and show it in database without any trouble as image below:

Git- Where to start? Import data into MySQL from CSV via PHP script

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×