[Catalyst] Catalyst and UTF-8

Mao DengFeng-e13751 e13751 at motorola.com
Wed Nov 29 01:17:35 GMT 2006


There is a good way do it.
You can run ("SET NAMES 'utf8'")  in your Catalyst DBIC Schema Model .
Just like this:
use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__->config(
    schema_class => 'MyApp',
    connect_info => [
        'dbi:mysql:MyApp',
        'my',
        'app',
        { AutoCommit=>1 },
        {
          on_connect_do => [
                        'SET  NAMES  utf8',
                           ],
        }

        
    ],
);


Thanks
 


 

-----Original Message-----
From: Jon [mailto:jon+catalyst at youramigo.com] 
Sent: Wednesday, November 29, 2006 9:04 AM
To: The elegant MVC web framework
Subject: Re: [Catalyst] Catalyst and UTF-8

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/


_______________________________________________
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