我有一个包含中文文章列表的数据库,当我尝试查询以获取所有文章名称时遇到问题,我看到的只是 ??? 而不是中文文本。
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});
}
Run Code Online (Sandbox Code Playgroud)
在您的连接字符串中也声明它应该使用 utf8
DBI->connect("DBI:mysql:host=localhost;database=articles", 'root', '',{mysql_enable_utf8 => 1});
Run Code Online (Sandbox Code Playgroud)
如果你有 utf8mb4
你必须{mysql_enable_utf8 => 1}
用{mysql_enable_utf8mb4 => 1}
编辑:
也看到这里UTF8 一路