我有一个包含中文文章列表的数据库,当我试图进行查询以获取所有文章名称时,我遇到了一个问题,我看到的只有?而不是中文文本。
my $db_connection = DBI->connect("DBI:mysql:host=localhost;database=articles", 'root', '');
my $con = $db_connection->prepare( "select * from articles" );
$con->execute;
while (my $infoD = $con->fetchrow_hashref())
{
$INFO{$infoD->{name}} .= decode('utf8', $infoD->{name});
}发布于 2020-06-30 04:24:39
还要在连接字符串中声明它应该使用utf8
DBI->connect("DBI:mysql:host=localhost;database=articles", 'root', '',{mysql_enable_utf8 => 1}); 如果你有utf8mb4
您必须用{mysql_enable_utf8mb4 => 1}替换{mysql_enable_utf8 => 1}
编辑:
另请参阅此处UTF8 all the way
https://stackoverflow.com/questions/62645833
复制相似问题