Hi,

I am quite lost at this utf8 issue:
I have a file that I opened with

open(my $KEYWORDS, "<:encoding(UTF-8)", $keywords_file)
as I read the rows I can print them to a log file
(that was opened using
open(my $fh, '>>:encoding(UTF-8)', $log_name)
and it looks ok.
I insert it into the 'text' field of a table that was created like this:

CREATE TABLE terms (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    text VARCHAR(255) NOT NULL,
    language_id INT NOT NULL,
    UNIQUE(text, language_id)
) ENGINE=MyISAM CHARSET=utf8;

Then I read it back using SELECT and when I try to print it to the log
file I get garbage there.

Calling decode('UTF-8', $t->{text}))  fixes the problem, but wonder if
I should not get the data back correctly?

I tried connecting to mysql with two different connections strings:

"DBI:mysql:database=$attr->{database};host=$attr->{host};mysql_enable_utf8=1",

"DBI:mysql:database=$attr->{database};host=$attr->{host}",

and I tried to call

$dbh->do('SET NAMES utf8');

immediately after the connection was established, but neither helped.

Using perl 5.18 on OSX with DBI 1.627 DBD::mysql 4.023
MySQL itself is 5.6.10

Oh and if I connect to the database using the mysql client,
it shows the text correctly.

your suggestions would be really appreciated

regards
    Gabor

Reply via email to