diff options
| author | Darkelarious <darkelarious@333networks.com> | 2016-11-20 19:30:58 +0100 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2016-11-20 19:30:58 +0100 |
| commit | 702d1898b012d6d992d66b996508610890bf2963 (patch) | |
| tree | 9556d890c4afdb7062f5b63277aa6b3d5c5d9d03 /lib/MasterServer/Database/Pg/dbCore.pm | |
| parent | c3f8d65a4fb1f5674557ee67cf7f74369df86ad1 (diff) | |
| download | MasterServer-Perl-702d1898b012d6d992d66b996508610890bf2963.tar.gz MasterServer-Perl-702d1898b012d6d992d66b996508610890bf2963.zip | |
Restore SQLite support
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbCore.pm')
| -rwxr-xr-x | lib/MasterServer/Database/Pg/dbCore.pm | 50 |
1 files changed, 50 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..90899f7 --- /dev/null +++ b/lib/MasterServer/Database/Pg/dbCore.pm @@ -0,0 +1,50 @@ + +package MasterServer::Database::Pg::dbCore; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT = qw| database_login |; + +################################################################################ +## login to the database with credentials provided in the config file. +## returns dbh object or quits application on error. +## +## Recommended database types: Postgresql, MySQL or SQLite. Warranty void if +## other database types are used. Use at your own risk. +################################################################################ +sub database_login { + my $self = shift; + + # get db info + my @db_type = split(':', $self->{dblogin}->[0]); + + # create the dbi object + my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => 1}); + + # verify that the database connected + if (defined $dbh) { + + # log the event + $self->log("info","Connected to the $db_type[1] 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(); + } + + # in case of any other error, return undef. + return undef; +} + +1; |
