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 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;

View File

@ -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});
}
}