Merge branch 'merge_db_connects' into storageareas

This commit is contained in:
Isaac Connor 2016-05-03 09:05:36 -04:00
commit 2ba18e14fc
2 changed files with 6 additions and 27 deletions

View File

@ -30,6 +30,7 @@ use warnings;
require Exporter; require Exporter;
require ZoneMinder::Base; require ZoneMinder::Base;
require ZoneMinder::Database;
our @ISA = qw(Exporter ZoneMinder::Base); our @ISA = qw(Exporter ZoneMinder::Base);
@ -82,12 +83,7 @@ BEGIN
} }
close( $CONFIG ); close( $CONFIG );
use DBI; my $dbh = zmDbConnect() or croak( "Can't connect to db" );
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 $sql = 'select * from Config'; my $sql = 'select * from Config';
my $sth = $dbh->prepare_cached( $sql ) or croak( "Can't prepare '$sql': ".$dbh->errstr() ); 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() ); my $res = $sth->execute() or croak( "Can't execute: ".$sth->errstr() );
@ -95,7 +91,6 @@ BEGIN
$Config{$config->{Name}} = $config->{Value}; $Config{$config->{Name}} = $config->{Value};
} }
$sth->finish(); $sth->finish();
#$dbh->disconnect();
if ( ! exists $Config{ZM_SERVER_ID} ) { if ( ! exists $Config{ZM_SERVER_ID} ) {
$Config{ZM_SERVER_ID} = undef; $Config{ZM_SERVER_ID} = undef;

View File

@ -30,6 +30,7 @@ use warnings;
require Exporter; require Exporter;
require ZoneMinder::Base; require ZoneMinder::Base;
require ZoneMinder::Database;
our @ISA = qw(Exporter ZoneMinder::Base); our @ISA = qw(Exporter ZoneMinder::Base);
@ -460,25 +461,7 @@ sub databaseLevel
{ {
if ( !$this->{dbh} ) if ( !$this->{dbh} )
{ {
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); $this->{dbh} = zmDbConnect();
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}
);
}
if ( !$this->{dbh} ) if ( !$this->{dbh} )
{ {
$databaseLevel = NOLOG; $databaseLevel = NOLOG;
@ -505,7 +488,8 @@ sub databaseLevel
{ {
if ( $this->{dbh} ) if ( $this->{dbh} )
{ {
$this->{dbh}->disconnect(); # $this->dbh is now the global dbh, so don't close it.
#$this->{dbh}->disconnect();
undef($this->{dbh}); undef($this->{dbh});
} }
} }