I wrote a script that allows users to upload/import lots of users at once using a CSV-file. I'm using MySQL's load data local infile to make this working:
$query = "LOAD DATA LOCAL INFILE $file INTO TABLE my_table
FIELDS TERMINATED BY $delimiter
LINES TERMINATED BY '\\n'
(email, name, organization);
But a user tried to import a document that contained the name Günther
. This was saved to the database as "G" (cutting of the rest). The document turned out to be in latin1
causing the problems. I don't want to bother my users with character sets and stuff.
I know about the character set
option that is supported by load data local infile. But, even though I don't get error when I put CHARACTER SET latin1
in my query, I want everything to be UTF-8. And What happens if I another users uses a file that's neither in UTF-8 or latin1?
So how do I found out in which character set the user uploaded document is and how do I convert it to UTF-8?