Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: multiple db connects

by jreades (Friar)
on Dec 21, 2000 at 21:00 UTC ( [id://47824]=note: print w/replies, xml ) Need Help??


in reply to Re: multiple db connects
in thread multiple db connects

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'});

Replies are listed 'Best First'.
Re: Re: Re: multiple db connects
by merlyn (Sage) on Dec 21, 2000 at 21:05 UTC
    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found