Service-Engine
view release on metacpan or search on metacpan
lib/Service/Engine/Data/Mysql.pm view on Meta::CPAN
$Log = $Service::Engine::Log;
# set some defaults
$attributes->{'raise_error'} ||= 0;
$attributes->{'port'} ||= '3306';
if (!$attributes->{'database'} || !$attributes->{'hostname'} || !$attributes->{'username'} || !$attributes->{'password'}) {
$Log->log({msg=>"mysql requires a database, hostname, username and password",level=>1});
} else {
my $datasource = 'DBI:mysql:' . $attributes->{'database'} . ':' . $attributes->{'hostname'} . ':' . $attributes->{'port'};
my $db = DBI->connect($datasource, $attributes->{'username'}, $attributes->{'password'},{ RaiseError => $attributes->{'raise_error'}, mysql_enable_utf8mb4 => 1, mysql_auto_reconnect => 1 });
$attributes->{'handle'} = $db;
$Log->log({msg=>"creating connection to $datasource",level=>3});
}
my $self = bless $attributes, $class;
return $self;
}
sub handle {
my ($self) = @_;
return $self->{'handle'};
}
sub reconnect {
my ($self) = @_;
my $datasource = 'DBI:mysql:' . $self->{'database'} . ':' . $self->{'hostname'} . ':' . $self->{'port'};
my $db = DBI->connect($datasource, $self->{'username'}, $self->{'password'},{ RaiseError => $self->{'raise_error'}, mysql_enable_utf8mb4 => 1, mysql_auto_reconnect => 1 });
$Log->log({msg=>"re-connecting to $datasource",level=>3});
$self->{'handle'} = $db;
return $self->{'handle'};
}
1;
( run in 0.338 second using v1.01-cache-2.11-cpan-00829025b61 )