Just tried to use "$sth->fetchall_arrayref" with UNICODE in mysql table - with "$dbh->{mysql_enable_utf8}=1" it always returns right encoded strings - so no need to encode/decode yourself.
Test details in <readmore> section below...
And about
"foreign accents"
- a lot of Monks, who give you answers on this site, do not speak English at home.
Creation of test mysql database "db1" and test table "tbl1" with unicode content:
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)
mysql> connect db1;
Connection id: 27
Current database: db1
mysql> create table tbl1 (id INT, str CHAR(80) CHARACTER SET utf8);
Query OK, 0 rows affected (0.08 sec)
mysql> insert into tbl1 values (0, 'äöüß');
Query OK, 1 row affected (0.00 sec)
mysql> insert into tbl1 values (1, 'Ƽ®©');
Query OK, 1 row affected (0.00 sec)
mysql> insert into tbl1 values (2, 'ĦǾǺǽ');
Query OK, 1 row affected (0.00 sec)
mysql> insert into tbl1 values (3, 'no unicode');
Query OK, 1 row affected (0.00 sec)
mysql> select * from tbl1;
+------+------------+
| id | str |
+------+------------+
| 0 | äöüß |
| 1 | Ƽ®© |
| 2 | ĦǾǺǽ |
| 3 | no unicode |
+------+------------+
3 rows in set (0.00 sec)
Test program:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use DBI;
use Data::Dumper;
my $dbh = DBI->connect("dbi:mysql:database=db1","","");
$dbh->{mysql_enable_utf8} = 1;
my $sth = $dbh->prepare('select * from tbl1');
$sth->execute;
my $ar = $sth->fetchall_arrayref;
$sth->finish;
print Dumper( $ar );
binmode(STDOUT, ':utf8');
my $str1 = $ar->[1]->[1];
print qq{"$str1" - }, (utf8::is_utf8($str1) ? 'UTF8' : 'ASCII'), qq{
+\n};
my $str3 = $ar->[3]->[1];
print qq{"$str3" - }, (utf8::is_utf8($str3) ? 'UTF8' : 'ASCII'), qq{
+\n};
Output:
$VAR1 = [
[
'0',
"\x{e4}\x{f6}\x{fc}\x{df}"
],
[
'1',
"\x{c6}\x{bc}\x{ae}\x{a9}"
],
[
'2',
"\x{126}\x{1fe}\x{1fa}\x{1fd}"
],
[
'3',
'no unicode'
]
];
"Ƽ®©" - UTF8
"no unicode" - ASCII