in reply to multiple db connects

not quite sure if i understand your question correctly, but i'd suggest doing something like that:
1) write a simple module the handles the database access:
package JasminesDB; use strict; use DBI; sub db_connect(){ $dbh = DBI->connect("DBI:Sybase:CRAP", "sa", "") || die ("Can't connect to database: $DBI::errstr"); return $dbh; } 1;
2) then, inside your script:
use JasminesDB; my $dbh = JasminesDB::db_connect();
yt, snowcrash

Replies are listed 'Best First'.
Re: Re: multiple db connects
by jreades (Friar) on Dec 21, 2000 at 21:00 UTC

    A useful addition to this might be to stash the returned db handle.

    If you're running Apache then then you can do something like the following to share a single connection amongst several scripts:

    if (! $Global::var{'dbh'}) { my $sdn = "DBI:mysql:database=$db;host=$host"; my $dbh = DBI->connect($sdn, $user, $pass) || die ("Unable to con +nect to DB: $DBI::errstr"); $Global::var{'dbh'} = $dbh; } return ($Global::var{'dbh'});
      You can't "share a single connection among multiple scripts" if they all live in separate spaces, whether you're using Apache or not!

      If you were talking about mod_perl's Apache::Registry "scripts" (really, handlers coded on the fly from script-like things), then you don't need to do any of this mess either. Just include Apache::DBI, and it autoshares for you!

      -- Randal L. Schwartz, Perl hacker