Hi

I have a cgi script running with mod_perl and mysql that uses utf8 input. As you
might know, it is important to issue the command

set names "utf8"

after initialising the mysql connection, or utf8 data can get garbled. I do this
successfully when running standrad cgi like this:

{
    my $dbh = 0;
    sub getDbh
    {
        unless ($dbh)
        {
            my $db = $Config::cfg->{'sqldb'};
            my $u = $Config::cfg->{'sqluser'};
            my $p = $Config::cfg->{'sqlpass'};
            $dbh = DBI->connect($db, $u, $p);
            #log("Common::getDbh - initialising");
            my $q = 'set names "utf8"';
            $q = $dbh->prepare($q);
            $q->execute();
        }
        return $dbh;
    }
}

and the same code works perfectly well under mod_perl - the database is
initialiased the first time a session is started. I deliberately made my cgi's
very small (almost all functionality tucked away in modules) and was careful
about uninitialised globals - this made the port to mod_perl very easy using
registry.

The problem is that the effect of "set names" seems to be lost after some period
of inactivity. Maybe the session has timed out - but it doesn't seem so, as data
is generally retrieved OK - only utf8 data which is non-Latin1 gets garbled, as
happened before I found out about the need to use "set names".

I don't get the same problem under perl cgi.

Has anyone any ideas what could be going on?


Reply via email to