0

Consider a table with three columns id,name and bgname where bgname is a cyrillic equivalent of name.The table is created with UTF-8 collation. After using the following:

<?php

    $sql = 'SELECT bgname FROM categories';
    function getZapisi($sql,$dbh) {
        foreach ($dbh->query($sql) as $row) {
            print $row['bgname'] . "<br/>";
        }
}
try {
    $dbh = new PDO("mysql:host=localhost;dbname=test", 'root', 'pass');
    /*** echo a message saying we have connected ***/
    getZapisi($sql,$dbh);
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }

?>

I get ??? from the query no matter if I use cp1251 or utf-8 collation for the bgname column. Thanks in advance

Konerak
  • 39,272
  • 12
  • 98
  • 118
George
  • 2,050
  • 6
  • 26
  • 36

3 Answers3

1

Check the encoding of your page. maybe you're getting correct results but the output html created by apache+php tells the browser to use some other encoding.

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
  • the encoding is cp-1251 default for bulgaria. Some idea of using the PHP iconv function? – George Oct 31 '11 at 18:48
  • That was posted before :) http://stackoverflow.com/questions/4794647/php-dealing-special-characters-with-iconv ... try changing the encoding in the browser to check that it is not using something else (try utf-8...). Also check this thread http://stackoverflow.com/questions/405684/php-mysql-with-encoding-problems – Alfabravo Oct 31 '11 at 18:55
1

Try to look at this : http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

David Bélanger
  • 7,400
  • 4
  • 37
  • 55
0

In fact the problem was terminated using:

$dbh = new PDO("mysql:host=localhost;dbname=test;", 'root', 'pass');
$dbh -> exec("set names cp1251");

Thanks for the effort

George
  • 2,050
  • 6
  • 26
  • 36