blob: 30fe3efd08f715f90b2fa879864caa60c2692a37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
|