$dbo = new PDO("mysql:host=localhost;dbname=database", "databaseuser",
"databasepassword", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dbo -> exec("set character_set_client='utf8'");
$dbo -> exec("set character_set_results='utf8'");
$dbo -> exec("set collation_connection='utf8_general_ci'");
$prepSnapRetrieve = $dbo->prepare(
"SELECT * FROM znc_log WHERE `nick` LIKE :u AND `tstamp` BETWEEN :t1 AND :t2"
);
$prepSnapRetrieve->execute(array(':u' => str_replace("|osu","", $_GET['u']),
':t1' => $_GET['sns'], ':t2' => $_GET['sne']));
$snapshotListing = $prepSnapRetrieve->fetchAll();
echo("Snapshot of ".$_GET['u']. "'s chat on ".strftime("%e/%m/%g",$_GET['sne']));
echo("<br><br>");
foreach($snapshotListing as $chat) {
echo "<i>" . " " . "[" . strftime("%H:%M:%S", $chat['tstamp']) . "]" .
"</i> " . " ><u>" . $chat['channel'] . "</u>< " . "(<b>" .
htmlspecialchars($chat['nick'])."</b>) ".htmlspecialchars($chat['message']);
echo("<br>");
}
这段代码的作用是解析并输出存储在UTF-8中的IRC数据 - 但是在回显时,任何Unicode内容都只会显示为:
??????
我已经查看了几个问题并包含了几个所谓的修复方法,但是似乎没有任何作用。另一个使用相同数据库的脚本完美地回显UTF-8内容,但它使用的是PHP的标准MySQL实现,而不是PDO。我做错了什么?