diff options
| author | Darkelarious <darkelarious@333networks.com> | 2015-11-08 15:42:27 +0100 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2015-11-08 15:42:27 +0100 |
| commit | 8b3d393e7755c167eebe4d9f7fc786074f12e9af (patch) | |
| tree | 756afc39bc4e5794c51b7a947ff3832b341cbb6b /lib/MasterServer/Database/mysql/dbCore.pm | |
| parent | 2c7d62f38944f61e7eafea155c6128521d16aed9 (diff) | |
| download | MasterServer-Perl-8b3d393e7755c167eebe4d9f7fc786074f12e9af.tar.gz MasterServer-Perl-8b3d393e7755c167eebe4d9f7fc786074f12e9af.zip | |
Full support for Postgres, MySQL and SQLite3 + minor bug fixes
Diffstat (limited to 'lib/MasterServer/Database/mysql/dbCore.pm')
| -rwxr-xr-x | lib/MasterServer/Database/mysql/dbCore.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/MasterServer/Database/mysql/dbCore.pm b/lib/MasterServer/Database/mysql/dbCore.pm new file mode 100755 index 0000000..30fe3ef --- /dev/null +++ b/lib/MasterServer/Database/mysql/dbCore.pm @@ -0,0 +1,44 @@ + +package MasterServer::Database::mysql::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. +################################################################################ +sub database_login { + my $self = shift; + + # create the dbi object + my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => $self->{db_print}}); + + # verify that the database connected + if (defined $dbh) { + + # log the event + $self->log("load","Connected to the MySQL 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; |
