Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Connecting to 2 mysql database in one script

by jfroebe (Vicar)
on Nov 21, 2008 at 22:31 UTC ( #725246=note: print w/ replies, xml ) Need Help??


in reply to Connecting to 2 mysql database in one script

You need a separate database handle (dbh) for each connection that is going to a different server. Some DBD drivers require a separate database handle for each connection.

$dbh1 = DBI->connect($DSN,$sqluser,$sqlpass) || die "Cannot connect: $DBI::errstr\n" unless $dbh1; $dbh2 = DBI->connect($DSN2,$sqluser2,$sqlpass2) || die "Cannot connect: $DBI::errstr\n" unless $dbh2;

You would then pass the appropriate db handle to any subroutines:

sub my_query { my $my_dbh = shift; my $query = shift; .... } my_query($dbh1, "select * from potatoes");

Jason L. Froebe

Blog, Tech Blog


Comment on Re: Connecting to 2 mysql database in one script
Select or Download Code
Re^2: Connecting to 2 mysql database in one script
by htmanning (Scribe) on Nov 21, 2008 at 22:55 UTC
    Thanks so much. I got it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://725246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-11-24 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (143 votes), past polls