aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/Pg/dbCore.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2015-02-09 07:58:06 +0100
committerDarkelarious <darkelarious@333networks.com>2015-02-09 07:58:06 +0100
commit5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb (patch)
treeb1a394f64ec7ec2cf69f33bceb54a5b51199c0a4 /lib/MasterServer/Database/Pg/dbCore.pm
parent6ac9d390e417b868b6ed79441b8cc6e1b2ebeb13 (diff)
downloadMasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.tar.gz
MasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.zip
receive UDP beacons, validate them and store with country indicator
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbCore.pm')
-rwxr-xr-xlib/MasterServer/Database/Pg/dbCore.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/MasterServer/Database/Pg/dbCore.pm b/lib/MasterServer/Database/Pg/dbCore.pm
new file mode 100755
index 0000000..c6e3182
--- /dev/null
+++ b/lib/MasterServer/Database/Pg/dbCore.pm
@@ -0,0 +1,44 @@
+
+package MasterServer::Database::Pg::dbCore;
+
+use strict;
+use warnings;
+use Exporter 'import';
+
+our @EXPORT = qw| database_login |;
+
+################################################################################
+## database_login
+## login to the database with credentials provided in the config file.
+## returns dbh object
+################################################################################
+sub database_login {
+ my $self = shift;
+
+ # create the dbi object
+ my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => 0});
+
+ # verify that the database connected
+ if (defined $dbh) {
+ # log the event
+ $self->log("database","Connected to the Postgres database.");
+
+ # turn on error printing
+ $dbh->{printerror} = 1;
+
+ # return the dbi object for further use
+ return $dbh;
+ }
+ else {
+ # fatal error
+ $self->log("fatal", "$DBI::errstr!");
+
+ # end program
+ $self->halt();
+ }
+
+ # unreachable
+ return undef;
+}
+
+1;