我使用的是漂亮的O和我ű字符匈牙利语言perl
与文字DBI
和MySQL
。所有数据库编码都是UTF8,我到处都使用utf8。该表采用utf8_general_ci编码,并且行也过于utf8_general_ci。
我试图将表和行编码更改为utf8_hungarian_ci和utf8_unicode_ci。这没有帮助。
当我使用PHPMyAdmin插入行时,似乎一切都很好,并且当我在控制台中签入时,它也很好。仅当我尝试在Perl DBI连接中使用时,才在这种情况下看到“?” 字符,而不是“ő”,“Ő”,“ű”和“Ű”字符。
这是我的perl脚本:
use uft8;
use DBI
my $db = DBI->connect("dbi:mysql:dbname=...", "user", "passwd",
{mysql_enable_utf8 => 1}) || die $DBI::error;
$db->do("INSERT INTO mytable (name) VALUES ('őűŐŰ')");
my $dbh = $db->prepare("SELECT name FROM mytable;");
$dbh->execute;
while (my @this = $dbh->fetchrow_array) {
print $this[0]."\n";
}
怎么了?DBI是否有特殊的参数或设置?或者
删除该mysql_enable_utf8
行,您的脚本对我有用。还请记住始终使用strict
和warnings
。
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use DBI;
my $dbh = DBI->connect(
"dbi:mysql:dbname=$dbname;host=$host;port=$port;",
$username,
$pw,
);
$dbh->do("INSERT INTO mytable (name) VALUES ('őűŐŰ')");
my $sth = $dbh->prepare("SELECT name FROM mytable");
$sth->execute;
while(my ($name) = $sth->fetchrow_array) {
print "$name\n"; # őűŐŰ
}
exit;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句