2

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?

yick04
  • 97
  • 1
  • 7
  • Are you sure that it isn't working? Could it be a data issue? Also, latin1 is not the only charset that will work for this situation (notably, UTF8 will work). – JRL Apr 17 '13 at 18:28
  • Here are some good information http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names – Erdem Ece Apr 17 '13 at 18:30
  • Hmm i always use utf8 but latin1 isn't supposed to be ISO-8859-1 ? Worth a try ? – Aurélien Grimpard Apr 17 '13 at 18:34
  • I use the second way after establishing the connection and it works. `pdo->query("SET NAMES 'utf8'")` – MahanGM Apr 17 '13 at 19:31

1 Answers1

3

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.

yick04
  • 97
  • 1
  • 7