From 67fe1ffa1a9d4b878bd820d9bfdade74cdc293ad Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Fri, 20 May 2016 09:15:18 +0200 Subject: Add first iteration of dbconfig package Should do a better job of the naming and the actual $dbh maintenance. I'm thinking that including nms::db should contain a $dbh perhaps. --- include/nms/dbconfig.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/nms/dbconfig.pm (limited to 'include/nms') diff --git a/include/nms/dbconfig.pm b/include/nms/dbconfig.pm new file mode 100644 index 0000000..b67c040 --- /dev/null +++ b/include/nms/dbconfig.pm @@ -0,0 +1,29 @@ +# vim:ts=8:sw=8 +use strict; +use warnings; +use utf8; +use DBI; +use Data::Dumper; +use JSON; +use nms; +package nms::dbconfig; + +use base 'Exporter'; +our @EXPORT = qw(%config); +our %config; +my $dbh; + +use Data::Dumper; + + +BEGIN { + $dbh = nms::db_connect(); + my $q2 = $dbh->prepare('select * from config order by id desc limit 1;'); + $q2->execute(); + while (my $ref = $q2->fetchrow_hashref()) { + %config = %$ref; + $config{'data'} = JSON::XS::decode_json($ref->{'data'}); + } + $dbh->disconnect(); +} +1; -- cgit v1.2.3