$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。我究竟做错了什么?