- elsif ( $db_driver eq 'Pg' ) {
- $encoding_query = "set client_encoding = 'UTF8';";
- $tz_query = qq(SET TIME ZONE = "$tz") if $tz;
- }
- my $schema = Koha::Schema->connect(
- {
- dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port".($tls_options? $tls_options : ""),
- user => $db_user,
- password => $db_passwd,
- %encoding_attr,
- RaiseError => $ENV{DEBUG} ? 1 : 0,
- PrintError => 1,
- unsafe => 1,
- quote_names => 1,
- on_connect_do => [
- $encoding_query || (),
- $tz_query || (),
- $sql_mode_query || (),
- ]
+
+ my $dbh = DBI->connect($dsn, $user, $pass, $attr);
+
+ if ($dbh) {
+ my @queries;
+ my $tz = $config->timezone;
+ $tz = '' if $tz eq 'local';
+
+ if ($driver eq 'mysql') {
+ push @queries, "SET NAMES 'utf8mb4'";
+ push @queries, qq{SET time_zone = "$tz"} if $tz;
+ if ( $config->get('strict_sql_modes')
+ || ( exists $ENV{_} && $ENV{_} =~ m|prove| )
+ || $ENV{KOHA_TESTING}
+ ) {
+ push @queries, q{
+ SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
+ };
+ } else {
+ push @queries, q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'}
+ }
+ } elsif ($driver eq 'Pg') {
+ push @queries, qq{SET TIME ZONE = "$tz"} if $tz;
+ push @queries, q{set client_encoding = 'UTF8'};