in reply to How to connect multiple databases with single sub routine connection using perl?

Oh so easy just watch. You change name of subroutine to connect_multiple and add sitemap liek this: You just watch so easy! xD
sub connect { my %site_map = ( Bang => [ qw(rate_bang_current) ], Nor => [ qw(rate_nor_current) ], Wilming => [ qw(rate_wilming_current) ], Lime => [ qw(rate_lime_current) ], ); $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 %site_map = ( Bang => [ qw(rate_bang_current) ], Nor => [ qw(rate_nor_current) ], Wilming => [ qw(rate_wilming_current) ], Lime => [ qw(rate_lime_current) ], ); 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 %site_map = ( Bang => [ qw(rate_bang_current) ], Nor => [ qw(rate_nor_current) ], Wilming => [ qw(rate_wilming_current) ], Lime => [ qw(rate_lime_current) ], ); 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 %site_map = ( Bang => [ qw(rate_bang_current) ], Nor => [ qw(rate_nor_current) ], Wilming => [ qw(rate_wilming_current) ], Lime => [ qw(rate_lime_current) ], ); my $dsn = "DBI:mysql:host=$host"; my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; }
  • Comment on Re: How to connect multiple databases with single sub routine connection using perl?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to connect multiple databases with single sub routine connection using perl?
by finddata (Sexton) on Mar 28, 2017 at 04:30 UTC
    Will it work.Becaue it will consider only one database and it will have the same database contents to other database also.
      Will it work.

      It will not.

      my $dbh = DBI->connect($dsn, $user, $pw) || die "ERROR: can't connect to database server\n"; return $dbh; $host = "dev.sp1.wilinlog.com";

      Regardless of the name of the function, it still has the problem: nothing after the first
          return $dbh;
      statement will ever be executed. The
              $host     = "dev.sp1.wilinlog.com";
      statement will never be executed. Please see return. There are some other problems, but those will only result in warnings and so are of relatively minor importance.

      My head hurts.


      Give a man a fish:  <%-{-{-{-<