#!/usr/bin/perl use DBI; use v5.10; use strict; use warnings; use feature 'say'; use Config::Simple; my %config = (); my $path = 'conf.ini'; sub mysql_con { Config::Simple->import_from("".$path."", \%config) or die Config::Simple->error(); my $dbh = DBI->connect("dbi:mysql::".$config{'MySQL.host'}.":".$config{'MySQL.port'}."", "".$config{'MySQL.user'}."", "".$config{'MySQL.pass'}."", { 'PrintError' => 1, 'RaiseError' => 1 , 'AutoInactiveDestroy' => 1 } ) or die "Could not connect to ". $config{'MySQL.host'} .": ". $DBI::errstr ."\n"; my $databases = $dbh->do("SHOW DATABASES LIKE '".$config{'MySQL.db'}."'") or die "Error: " .dbh->errstr. "\n"; $dbh->disconnect() or warn "Error disconnecting: $DBI::errstr\n"; if ($databases eq 1) { return "Database: ". $config{'MySQL.db'} . " exists not creating: ". $config{'MySQL.db'} .""; } return "Database: ". $config{'MySQL.db'} . " does not exist create: ". $config{'MySQL.db'} .""; } say mysql_con();