Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Connecting to 2 mysql database in one script

by jfroebe (Parson)
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 avoiding work at the Monastery: (7)
As of 2015-07-04 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls