projecteq-projecteqquests/plugins/MySQL.pl

38 lines
908 B
Perl
Raw Permalink Normal View History

#::: Akkadius
#::: Description: These plugins are MySQL loaders in use with Perl DBI
#::: For plug and play, LoadMysql will load your database credentials from eqemu_config.json
sub LoadMysql {
use DBI;
use DBD::mysql;
use JSON;
2018-01-13 17:39:53 -06:00
my $json = new JSON();
#::: Load Config
2018-01-13 17:39:53 -06:00
my $content;
open(my $fh, '<', "eqemu_config.json") or die "cannot open file $filename"; {
local $/;
$content = <$fh>;
}
close($fh);
#::: Decode
2018-01-13 17:39:53 -06:00
$config = $json->decode($content);
#::: Set MySQL Connection vars
2018-01-13 17:39:53 -06:00
$db = $config->{"server"}{"database"}{"db"};
$host = $config->{"server"}{"database"}{"host"};
$port = $config->{"server"}{"database"}{"port"};
2018-01-13 17:39:53 -06:00
$user = $config->{"server"}{"database"}{"username"};
$pass = $config->{"server"}{"database"}{"password"};
#::: Map DSN
$dsn = "dbi:mysql:$db:$host:$port";
#::: Connect and return
$connect = DBI->connect($dsn, $user, $pass);
return $connect;
2018-01-13 17:39:53 -06:00
}