Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: OT? Character set issues with MySQL/CGI::Application

by Corion (Pope)
on Jul 25, 2008 at 06:16 UTC ( #700033=note: print w/replies, xml ) Need Help??

in reply to OT? Character set issues with MySQL/CGI::Application

The issue is with consistency. You need to identify what charset is for all places where you handle your data:

  1. Data entry into Application?
  2. Data entry into the DB?
  3. Data query and display through the DB command line tool?
  4. Data retrieval and mixing with the template?
  5. Data output to to the browser?

In all these stages, a mistake/mixup can happen which will break the chain. To identify it, you will have to look at hexdumps of the data at various stages to see whether the data is (still) how you want it. Especially Templates are prone to encoding mixups in my experience.

  • Comment on Re: OT? Character set issues with MySQL/CGI::Application

Replies are listed 'Best First'.
Re^2: OT? Character set issues with MySQL/CGI::Application
by cLive ;-) (Prior) on Jul 25, 2008 at 06:41 UTC

    When I inserted the Espaņol into the DB, I used a manual query in the mysql shell and copied and pasted it from a web page.

    I've been trying to "fix" hte table tonight by playing around with the character set, but

    ALTER TABLE Language CONVERT TO latin1;

    has no effect on the data. I still have to pipe it through Encode::decode.

      How do you know what encoding the mysql shell uses? How do you know what your console uses as encoding? How do you know what the web browser did with the encoded data before putting it into the clipboard?

      You need to eliminate as many conversion steps as possible and check the consistency of the remaining. I wouldn't rely on MySQL to upgrade or change the encoding. Use Scalar::UtilDevel::Peek to dump the scalars before sending them to the DB to see whether Perl encodes them as UTF8 or Latin1. Then retrieve them via DBI and check the encoding again. It should be the same as you put in, but maybe it isn't. Also, the strings should ideally be bytewise identical.

      If Encode::decode() works, then likely your data is in UTF8 when you retrieve it from MySQL. If it already is in UTF8 when you put it in, it could be an idea to keep all data in UTF8 throughout your application and just convert at the output stage to Latin1.

      Update: moritz pointed out that I want Devel::Peek, not Scalar::Util

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://700033]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2018-06-25 16:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (127 votes). Check out past polls.