【问题标题】:How to read Chinese text from a database using DBI?如何使用 DBI 从数据库中读取中文文本?
【发布时间】:2020-10-20 01:42:36
【问题描述】:

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

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

【问题讨论】:

    标签: mysql perl


    【解决方案1】:

    在你的连接字符串中声明它应该使用 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

    【讨论】:

      猜你喜欢
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多