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

In reply to Re: Mugged by UTF8, this CANNOT be right by nif
in thread Mugged by UTF8, this CANNOT be right by tosh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.