[Catalyst] Catalyst and UTF-8

Jon jon+catalyst at youramigo.com
Wed Nov 29 01:03:46 GMT 2006


In my experience, you're best off treating all of your data internally
as UTF-8, by placing

use encoding 'utf8'

ONCE in your code.  Only once! - best in your top level MyApp.pm.  (I've
ended up with characters being double and triple encoded when use
encoding 'utf8' has been included in multiple library modules, against
the perldoc recommendations).

To get utf8 data out of mysql, use

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

Mysql will then deliver the data to you in utf8 regardless of the
character set definition in the database tables.

I don't know if there is a better high level way to do this in
DBIx::Class, but should work if you get the dbh from
DBIx::Class::Storage::DBI.

If you do this then it shouldn't be necessary to use UTF8Columns.

-- 

Jon

On Tue, 2006-11-28 at 22:34 -0200, Renan Valente Rangel wrote:
> Hi,
> 
> I am trying to use MySQL with DBIC to get some data in UTF-8, but I
> only see ISO-8859-1 data in my browser. Using ut8::is_ut8() in the
> data that comes from DBIC, it is false.
> I have the latest DBI, DBIx::Class and DBD::mysql from CPAN. 
> 
> I have tried use UTF8Columns in the result classe of DBIC and set all
> columns with utf8_columns(), but it still not work.
> 
> What can I try to solve this problem?
> 
> Thanks
> 
> -- 
> Renan 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list