1

I have a mysql table that is full of text that is latin encoded. I know this because even though I have the table defined as being UTF-8 encoded, and the headers sent are set to UTF-8, I receive the ugly question mark in the black diamond. The only way that I can get my data to be displayed correctly is by changing my headers to use ISO-8859-1 encoding instead.

I have tried every suggestion that I can find on SO and throughout the net, but none have worked so far.

I have attempted to do as this author suggests: https://stackoverflow.com/a/5232411/102067, but even though I was able to read the file correctly with my text reader, it didn't display properly on the website.

I am at a complete loss and open to suggestions as to how to solve this problem.

Thank you.

Community
  • 1
  • 1
ServAce85
  • 1,602
  • 2
  • 23
  • 51
  • 2
    Try following this: [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jan 31 '12 at 23:35

1 Answers1

1

I have finally found the answer thanks to @deceze's suggestion.

For anyone that is having the same problem, here is what I did...

I am using PDO to connect to my database and I wasn't aware that the default connection encoding is Latin if left unspecified. Thus, I had to specify that I wanted a connection utilizing UTF-8 encoding.

With this additional parameter, my connection now looks like:

$pdo = new PDO('mysql:dbname=encoding_test;host=localhost', 'user', 'pass',
            array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ServAce85
  • 1,602
  • 2
  • 23
  • 51