Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I was wondering how it is possible to establish connections to multiple SQL servers. Here's what I need to do. I have a news script which "require"s two files, cra_vbulletin.pl ( allows integration with vBulletin ) and cra_sql.pl ( replaces flat-text with SQL backend ). Both of these must access different DB's on different servers, with different login information. The connections themselves have to be established from with the files. One final catch: the routine to include the files simply reads a directory, so the files may not always be called in the same order. Also, obviously both files would have to include "use DBI;" Code samples needed! thanks

Replies are listed 'Best First'.
Re: Multiple connections in DBI
by seesik (Initiate) on Sep 21, 2001 at 02:58 UTC
    frankly, we need code samples from you. i haven't a clue what vBulletin is (/me smells a pre-made), but you should have no problem whatsoever establishing multiple connections to databases.
    my %dbs; $dbs{$sid_0} = DBI->connect("dbi::$driver0", $user0, $pass0) || die "failed to establish connection to $sid_0 : $DBI::errstr\n"; $dbs{$sid_1} = DBI->connect("dbi::$driver", $user1, $pass1) || die "failed to establish connection to $sid_1 : $DBI::errstr\n"; ... $sth_0 = $dbs{$sid_0}->prepare... $sth_1 = $dbs{$sid_1}->prepare...
    ad nauseum.

    obviously using a hash is arbitrary; it just makes it easy to track your connections by some meaningful name.

Re: Multiple connections in DBI
by Trimbach (Curate) on Sep 21, 2001 at 03:00 UTC
    You can create as many connections to as many different databases as you like using DBI and the connect() method to create your objects. There's tons of examples in the DBI documentation... why don't you give it a shot and if you're having trouble post what you have and we'll look at it? :-D

    Gary Blackburn
    Trained Killer

Re: Multiple connections in DBI
by Anonymous Monk on Sep 21, 2001 at 05:10 UTC
    vBulletin is a SQL-based forum script. Much like Ultimate Bulletin Board and it's ilk. For a running vBulletin forum, check out http://www.siteownersforums.com