Neid has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have some kind of deamon which keeps persistent connection 
with database.

I'm using this kind of pseudo code:

$dbh = connect

# to save/receive utf8 data
$dbh->do( "SET NAMES 'utf8'" );    

# enable auto reconnect
$dbh->{mysql_auto_reconnect} = 1;



I have noticed that after some time when driver performs
autoreconnection it starts using latin1 connection!

Is there a way to setup some kind of hook when driver reconnects to send "SET NAMES 'utf8'" query?
Or can you point me a different solution?

Thanks
  Neid

Replies are listed 'Best First'.
Re: mysql_auto_reconnect and utf8
by hipowls (Curate) on Jan 25, 2008 at 22:10 UTC

    In the connect method set the attribute mysql_enable_utf8 to true.

      Hi
      
      But documentation says that 'mysql_enable_utf8':
      'This option is experimental and may change in future versions.'
      
      So it safe to use?
      
      Neid
      
        Let's just say that not using it will cause more trouble than it's worth, and that if the option should eventually disappear or change it shouldn't be much work to change your code to adapt. Database drivers don't update themselves; just check when you install a new version.

        You should assume that all code using utf-8 with DBD::mysql on current versions will work better when that option is used. I'm using it in a couple of fairly large systems and the only real issue I've had is that it's not complete - you still have to make sure data specified for UTF-8 columns is really utf-8 before sending queries.

        Since 4.004 using the option will as far as I know at least guarantee you'll get your data back with correct status for the utf-8 marker of each column, for every type of column. Nothing else will give you that guarantee.

Re: mysql_auto_reconnect and utf8
by Joost (Canon) on Jan 25, 2008 at 22:15 UTC