Re: DBD::mysql and UTF-8
- From: "YorHel" <yorhel@xxxxxxxxx>
- Date: 13 Aug 2005 12:31:29 -0700
xhoster@xxxxxxxxx wrote:
> yorhel@xxxxxxxxx wrote:
> > Hello,
> >
> > I have a perl (5.8.7) application which tries to put UTF-8 data in a
> > mysql (4.1.13) database (with database collation = utf8_general_ci),
> > using DBI (1.48) and DBD::mysql (3.0002), like this:
> >
> > use Encode;
> > my $utf8data = decode('UTF-8', $somevar);
>
> Why are you doing this? Isn't $somevar already UTF-8?
According to Devel::Peek, no
>
>
> > my $rows = $dbh->do("UPDATE test SET text = '$utf8data' WHERE name =
> > 'test'");
> >
> > I can get the same data from the database like this:
> >
> > my $obj = $dbh->prepare("SELECT text FROM test WHERE name = 'test'");
> > $obj->execute();
> > my $result = ($obj->fetchrow_array())[0];
> > $result = decode('UTF-8', $result);
>
> Now you've chain-called decode twice. Aren't encode and decode
> usually used as complements of each other, not chained with
> themselves only?
>
well... I don't get the exact same data when putting something in de
DB, as getting something from the DB, after a lot of testing, this is
the only way I found.
>
> > That works like a charm within perl, the problem is though, that the
> > data isn't really stored as I want it.
>
> How do you know?
>
Sorry, forgot to mention that the command-line 'mysql' gives me the
same output as phpMyAdmin, and I have added
'default-character-set=utf8' at /etc/my.cnf, so I can assume that that
client gives me the "real" output.
> > When I fetch the same data with
> > php (phpMyAdmin), I only get weird characters.
>
> So what makes you think this is a Perl problem and not a php problem?
>
> > And when I add data with
> > phpMyAdmin to the table, I can't get that data in valid UTF-8 in perl,
> > but I only get weird characters.
> > Is there a way to work with UTF-8 and mysql in perl?
>
> You just reported that your method works like a charm with mysql and Perl.
>
But I also like to use other tools on the same database, so the IS a
problem :)
> > without getting
> > weird results?
>
> It seems like the weird results are coming from php, not Perl.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
.
- Follow-Ups:
- Re: DBD::mysql and UTF-8
- From: xhoster
- Re: DBD::mysql and UTF-8
- References:
- DBD::mysql and UTF-8
- From: yorhel
- Re: DBD::mysql and UTF-8
- From: xhoster
- DBD::mysql and UTF-8
- Prev by Date: Re: DBD::mysql and UTF-8
- Next by Date: Re: DBD::mysql and UTF-8
- Previous by thread: Re: DBD::mysql and UTF-8
- Next by thread: Re: DBD::mysql and UTF-8
- Index(es):
Relevant Pages
|