From 5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Mon, 9 Feb 2015 07:58:06 +0100 Subject: receive UDP beacons, validate them and store with country indicator --- lib/MasterServer/Database/Pg/dbCore.pm | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 lib/MasterServer/Database/Pg/dbCore.pm (limited to 'lib/MasterServer/Database/Pg/dbCore.pm') 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; -- cgit v1.2.3