From 55d58a140e8f376bd6264912a0ddabc66f3a5c38 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 3 May 2016 08:57:51 -0400 Subject: [PATCH 1/2] instead of code duplication for opening the db, use zmDbConnect everywhere --- scripts/ZoneMinder/lib/ZoneMinder/Logger.pm | 24 ++++----------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index a6a82db87..4c5acac2b 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -30,6 +30,7 @@ use warnings; require Exporter; require ZoneMinder::Base; +require ZoneMinder::Database; our @ISA = qw(Exporter ZoneMinder::Base); @@ -460,25 +461,7 @@ sub databaseLevel { if ( !$this->{dbh} ) { - my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); - - if ( defined($port) ) - { - $this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$host - .";port=".$port - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); - } - else - { - $this->{dbh} = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$Config{ZM_DB_HOST} - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ); - } + $this->{dbh} = zmDbConnect(); if ( !$this->{dbh} ) { $databaseLevel = NOLOG; @@ -505,7 +488,8 @@ sub databaseLevel { if ( $this->{dbh} ) { - $this->{dbh}->disconnect(); + # $this->dbh is now the global dbh, so don't close it. + #$this->{dbh}->disconnect(); undef($this->{dbh}); } } From 30f34a6f49f071b8f2f912d1a177cc7ab13a4a05 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 3 May 2016 08:59:40 -0400 Subject: [PATCH 2/2] instead of code duplication for opening the db, use zmDbConnect everywhere --- scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in index 3a226cdc8..4be86e962 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/Config.pm.in @@ -30,6 +30,7 @@ use warnings; require Exporter; require ZoneMinder::Base; +require ZoneMinder::Database; our @ISA = qw(Exporter ZoneMinder::Base); @@ -82,12 +83,7 @@ BEGIN } close( $CONFIG ); - use DBI; - my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME} - .";host=".$Config{ZM_DB_HOST} - , $Config{ZM_DB_USER} - , $Config{ZM_DB_PASS} - ) or croak( "Can't connect to db" ); + my $dbh = zmDbConnect() or croak( "Can't connect to db" ); my $sql = 'select * from Config'; my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute() or croak( "Can't execute: ".$sth->errstr() ); @@ -95,7 +91,6 @@ BEGIN $Config{$config->{Name}} = $config->{Value}; } $sth->finish(); - #$dbh->disconnect(); if ( ! exists $Config{ZM_SERVER_ID} ) { $Config{ZM_SERVER_ID} = undef;