Re: DBD::mysql and UTF-8




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

.



Relevant Pages

  • Re: Perl opting for double-byte chars?
    ... sure Unicode has something to do with your problem, ... Without knowing the version of Perl you're using and the platform ... The UTF-8 encoding uses variable-length character ... perldoc Encode ...
    (comp.lang.perl.misc)
  • Re: DBD::mysql and UTF-8
    ... Isn't $somevar already UTF-8? ... Aren't encode and decode ... > That works like a charm within perl, the problem is though, that the ... So what makes you think this is a Perl problem and not a php problem? ...
    (comp.lang.perl.modules)
  • Re: What are the differences between Perl and PHP when handling with Web pages
    ... What are the differences between Perl and PHP? ... anyway for the sake of good programming practice. ... I end up using PHP more for web development than PHP. ...
    (perl.beginners)
  • Re: Can a Perl Programmer Pick up PHP quickly?
    ... PHP is not easier compared to Perl. ... a language with fewer features is going to be easier to ... You can't call documentation guessed after the source not good ...
    (comp.lang.perl.misc)
  • Re: Face lift survey
    ... But PHP, I think, integrates html code a better way. ... you still have to do a perl script and then put ... Perl CGI programming! ...
    (perl.beginners)