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; }
In reply to How to connect multiple databases with single sub routine connection using perl? by finddata
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |