Horror with utf8 and LAMP ( perl ) web application contiunued:
We need to take care of mysql connection, so it is ut8 – ready:
if (my $dbh = DBI->connect(“DBI:mysql:database=”.$name.’;host=’.$hostname, $user, $password,
{
RaiseError => $raise,
# AutoCommit => 1,
mysql_enable_utf8 => 1,
on_connect_do => [ "SET NAMES 'utf8'", "SET CHARACTER SET +'utf8'" ],
})) {$dbh->{‘mysql_enable_utf8′} = 1;
return $dbh; # DBI database handler
}
We also must make sure that our tables are unicode:
CREATE TABLE `foo` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
….) DEFAULT CHARSET=utf8
And remember, that utf8 chars may take more space than normal – so prepare longer varchars in tables and be prepared for problem with indexes, like this: Specified key was too long; max key length is 1000 bytes – see http://bugs.mysql.com/bug.php?id=4541
See also:
- Utf8 in web perl application (LAMP)
- Utf8 in web perl application (LAMP) – part 2 – Encode
- Utf8 in web perl application (LAMP) – binmode, charset
- Utf8 horror at LAMP – accept charset
- Perl WTFs – last in function

