Reputation: 2110
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
Upvotes: 0
Views: 304
Reputation: 2110
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
Upvotes: 0
Reputation: 7438
Try to look at this : http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
Upvotes: 1
Reputation: 7589
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.
Upvotes: 1