Reputation: 12246
I'm trying to import a CSV file into a mysql table. The entire database has a utf8_unicode_ci encoding. The CSV file also has an UTF8 encoding. But when I try to run the following it just shows blank characters in the table instead of the special character:
$query = "LOAD DATA LOCAL INFILE 'mycsvfile.csv' INTO TABLE location_temp
CHARACTER SET UTF8
FIELDS TERMINATED BY ';'
ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'";
$parameters = array ();
$connection->QueryExec ( $query, $parameters ); //Connection class
In the table above I only have one column location, the content of the csv file is: "ä";
I've also tried to change the value of the csv to "testthät";
in the table then comes: testth
it just skips after the special character.
EDIT: This is how I create my database connection:
try {
$this->conn = new PDO ( "mysql:host=" . $host . ";charset=utf8;dbname=" . $database, $user, $pass );
$this->conn->exec ( "set names utf8" );
} catch ( PDOException $e ) {
echo "Something went wrong while connecting to the database: " . $e->getMessage ();
}
Thanks in advance
Upvotes: 2
Views: 2997
Reputation: 142528
The truncation indicates that it is not utf8. You say it is cp1252? Check SHOW COLLATION LIKE 'CP125%';
If you don't see cp1252, then latin1
is probably what you need.
Change the LOAD ...
to specify cp1252 (or latin1) and in the dsn for the connection via PDO. (That is better than using SET NAMES
.)
The principles:
Upvotes: 1