# 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
+ ## correct name for db_scheme
my $db_driver = db_scheme2dbi($context->config("db_scheme"));
my $db_name = $context->config("database");
$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.
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.
diag "Testing syspref caching.";
-my $dbh = C4::Context->dbh;
-$dbh->disconnect;
-
my $module = new Test::MockModule('C4::Context');
$module->mock(
'_new_dbh',
);
my $history;
-$dbh = C4::Context->dbh;
+$dbh = C4::Context->dbh({ new => 1 });
$dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ];
$dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ];