gpt4 book ai didi

mysql - 如何使用 DBI 从数据库中读取中文文本?

转载 作者:行者123 更新时间:2023-12-03 21:12:46 25 4
gpt4 key购买 nike

我有一个包含中文文章列表的数据库,当我尝试查询以获取所有文章名称时遇到问题,我看到的只是 ???而不是中文文本。

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});
}

最佳答案

在您的连接字符串中也声明它应该使用 utf8

DBI->connect("DBI:mysql:host=localhost;database=articles", 'root', '',{mysql_enable_utf8 => 1}); 
如果你有 utf8mb4
你必须更换 {mysql_enable_utf8 => 1}{mysql_enable_utf8mb4 => 1}编辑:
另见此处 UTF8 all the way

关于mysql - 如何使用 DBI 从数据库中读取中文文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62645833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com