Re: utf8 and mysql

Tim Bunce <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <[email protected]>
On Thu, Aug 01, 2013 at 10:28:41AM +0300, Gabor Szabo wrote:
> On Wed, Jul 31, 2013 at 7:39 PM, Meir Guttman <[email protected]> wrote:
> > Dear Gabor,
> > You must include «mysql_enable_utf8 => 1» hash record in the connection attributes used when you create the DBI handle
> > my %conn_attrs = (RaiseError    => $RaiseError,
> >                   PrintError    => $PrintError,
> >                   AutoCommit    => $AutoCommit,
> >                   mysql_enable_utf8 => 1);
> > my $dbh = DBI->connect
> >          ($dsn, $user_name, $password, \%conn_attrs);
> 
> That worked. Great. Thank you!
> 
> This was entirely unclear to me from the docs that it needs to be a
> separate key as I looked a couple of lines above the documentation of
> mysql_enable_utf8 where it showed another key, mysql_use_result, being
> in the actual connection string.

That seems like a bug.
Either it's a bug that mysql_enable_utf8=1 in the DSN should work,
or it's a bug that unrecognized items in the DSN should warn.

There is another, little-used, DSN style that might help:

    DBI:mysql(mysql_enable_utf8=1):database=$attr->{database};host=$attr->{host}

The attributes after the driver name are extracted by the DBI and
applied to the $dbh returned from the drivers' connect method.
(So can't be used for attributes that need to be applied before
the connection is established.)

You can see it documented in https://metacpan.org/module/DBI#parse_dsn
and the connect section below it.

Tim.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.