[Catalyst] Special characters and MySQL issue

Jonathan Rockway jon at jrock.us
Fri Aug 25 17:22:53 CEST 2006


What happens if you 'use encoding "iso-8859-1"' at the top of the script
that accepts this data?

BTW my suggestion is to not send latin-1 to the browser.  Use the
"Encode" module to convert from latin-1 bytes to perl characters, and
then use the C::P::Unicode module to send UTF-8 to the browser.  When
the request comes in, it will be in UTF-8, and C::P::Unicode will decode
the UTF-8 octets to perl characters.  When you're talking to the
database, use "Encode" to encode perl characters to latin-1.  This will
throw an exception when you get invalid characters (like the umlaut).
Since your database can't handle umlauts, I think this is a better
result than returning random rows (or no rows at all).

I can be more detailed if you want, just let me know.

Relevant documentation:

perldoc utf8
perldoc encoding
perldoc Encode
man perluniintro
man perlunicode
man perllocale

Good luck.  And remember that utf8::encode decodes, and utf8::decode
encodes.  That took me a while to understand.

(decode takes UTF-8 octets and encodes them to perl characters)
(encode takes perl characters and decodes them to UTF-8 octets)

Regards,
Jonathan Rockway

Tobias Kremer wrote:
> I have my content-type header set to ISO-8859-1 because I'm dealing with
> legacy data from a latin1 encoded MySQL database (otherwise data from the
> database is not displayed correctly in the browser). There's a form on my
> site for searching users by attribute. Now here's the problem:



More information about the Catalyst mailing list