@@ -, +, @@ ping $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh; --- C4/Context.pm | 19 +++++++++++++------ installer/install.pl | 2 -- misc/cronjobs/j2a.pl | 1 - sms/sms_listen.pl | 1 - t/db_dependent/Context.t | 5 +---- 5 files changed, 14 insertions(+), 14 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -788,16 +788,14 @@ sub _new_Zconn { # Internal helper function (not a method!). This creates a new # database connection from the data given in the current context, and # returns it. +our $db_driver = 'mysql'; sub _new_dbh { ## $context - ## correct name for db_schme - my $db_driver; + ## correct name for db_schme if ($context->config("db_scheme")){ $db_driver=db_scheme2dbi($context->config("db_scheme")); - }else{ - $db_driver="mysql"; } my $db_name = $context->config("database"); @@ -823,6 +821,10 @@ sub _new_dbh $dbh->{RaiseError} = 0; } + if ( $db_driver eq 'mysql' ) { + $dbh->{mysql_auto_reconnect} = 1; + } + my $tz = $ENV{TZ}; if ( $db_driver eq 'mysql' ) { # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config. @@ -857,10 +859,15 @@ possibly C<&set_dbh>. sub dbh { my $self = shift; + my $params = shift; my $sth; - if (defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { - return $context->{"dbh"}; + unless ( $params->{new} ) { + if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { + return $context->{"dbh"}; + } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { + return $context->{"dbh"}; + } } # No database handle or it died . Create one. --- a/installer/install.pl +++ a/installer/install.pl @@ -382,8 +382,6 @@ elsif ( $step && $step == 3 ) { ); } } - - $dbh->disconnect; } } else { --- a/misc/cronjobs/j2a.pl +++ a/misc/cronjobs/j2a.pl @@ -234,4 +234,3 @@ if ( not $noaction) { } $sth->finish( ); } -$dbh->disconnect(); --- a/sms/sms_listen.pl +++ a/sms/sms_listen.pl @@ -108,7 +108,6 @@ foreach my $user(@phones){ } print $reply; } -$dbh->disconnect; sub send_message { my ($mes,$message,$smsid)=@_; --- a/t/db_dependent/Context.t +++ a/t/db_dependent/Context.t @@ -44,9 +44,6 @@ ok($config = $koha->{config}, 'Getting $koha->{config} '); diag "Testing syspref caching."; -my $dbh = C4::Context->dbh; -$dbh->disconnect; - my $module = new Test::MockModule('C4::Context'); $module->mock( '_new_dbh', @@ -58,7 +55,7 @@ $module->mock( ); my $history; -$dbh = C4::Context->dbh; +$dbh = C4::Context->dbh({ new => 1 }); $dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ]; $dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ]; --