yick04
yick04

Reputation: 97

How do I specify charset with PDO?

I'm migrating data from one database to another using PDO. Unfortunately, I need to set the charset to latin1 or else the French characters get messed up. I've done my research and apparently this is supposed to work:

$DBH = new PDO("mysql:host=$host;dbname=$dbname;charset=latin1", $user, $pass);

but unfortunately, it doesn't. I've also tried:

$DBH->exec("set names latin1");

as well as

$DBH->exec("SET NAMES 'latin1';
            SET CHARACTER
            SET latin1;");

after the initializing statement, but haven't found any luck. Any tips?

Upvotes: 2

Views: 7910

Answers (1)

yick04
yick04

Reputation: 97

thanks for all the help.

I figured out what the problem was. I was doing it right, however when I was inserting the data into the new database I had to re-set the charset to utf8. I'm sure you guys would have known had I been more clear in my question, haha.

Upvotes: 3

Related Questions