finddata has asked for the wisdom of the Perl Monks concerning the following question:
In the above sub routine i had tried to connect mapped database inside the subroutine.But i hardcoded manually each database.Now those databases are not fetching the contents properly because it is displaying only the rate_bang_current database contents for all other four DATABASES.How can i automatically select the database using perl without hard coding the database names and connection manually.my %site_map = ( Bang => [ qw(rate_bang_current) ], Nor => [ qw(rate_nor_current) ], Wilming => [ qw(rate_wilming_current) ], Lime => [ qw(rate_lime_current) ], ); sub connect { $host = "dev.sp1.wilinlog.com"; $database = "rate_bang_current" ; $user = "senthom" ; $pw = "ask123"; my $dsn = "DBI:mysql:host=$host"; my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; $host = "dev.sp1.wilinlog.com"; $database = "rate_nor_current" ; $user = "senthom" ; $pw = "ask123"; my $dsn = "DBI:mysql:host=$host"; my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; $host = "dev.sp1.wilinlog.com"; $database = "rate_wilming_current" ; $user = "senthom" ; $pw = "ask123"; my $dsn = "DBI:mysql:host=$host"; my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; $host = "dev.sp1.wilinlog.com"; $database = "rate_lime_current" ; $user = "senthom" ; $pw = "ask123"; my $dsn = "DBI:mysql:host=$host"; my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to connect multiple databases with single sub routine connection using perl?
by Corion (Patriarch) on Mar 27, 2017 at 11:16 UTC | |
Re: How to connect multiple databases with single sub routine connection using perl?
by hippo (Bishop) on Mar 27, 2017 at 11:13 UTC | |
Re: How to connect multiple databases with single sub routine connection using perl?
by Anonymous Monk on Mar 27, 2017 at 15:47 UTC | |
Re: How to connect multiple databases with single sub routine connection using perl?
by Anonymous Monk on Mar 27, 2017 at 19:50 UTC | |
by finddata (Sexton) on Mar 28, 2017 at 04:30 UTC | |
by AnomalousMonk (Archbishop) on Mar 28, 2017 at 06:59 UTC |
Back to
Seekers of Perl Wisdom