Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^4: How to share DBI connections between objects?

by adrianh (Chancellor)
on Mar 27, 2007 at 12:38 UTC ( #606751=note: print w/replies, xml ) Need Help??

in reply to Re^3: How to share DBI connections between objects?
in thread How to share DBI connections between objects?

I'm not sure I understand. I presume you're objecting to My->Db, right?

Kinda. I'm objecting to their being one hard coded $dbh that everything uses. This makes it harder to, for example, swap in a test database, or maybe decide to split a system over multiple databases.

This isn't really just an issue of database handles, but all "shared" configuration information.

Instead I pass configuration objects in at object construction time, or use factories like Rose::DB to allow me to switch things around more easily.

  • Comment on Re^4: How to share DBI connections between objects?

Replies are listed 'Best First'.
Re^5: How to share DBI connections between objects?
by f00li5h (Chaplain) on Mar 28, 2007 at 00:21 UTC

    I've been meaning to read up on Rose::DB, so this seems a sensible time to do it.

    In my implementation My->Db did actually get it's connect info from My->get_config('db'); but that still does not allow individual things within My to get connections to other databases, or to allow for injecting of mock database objects for testing without nastyness.

    hrm, good thing you mentioned it adrianh, or I'd just have kept plodding along with this implementation.

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606751]
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already
[perldigious]: Snowshoeing time stevieb? I need to buy a pair so I can walk my German Shepherd properly through the country.
[stevieb]: yeah, I snowshoe a fair amount in the mountains. I also use spikes similar to these very often as well
[perldigious]: Discipulus: alternate link
[stevieb]: LOL you can easily replace "Helsinki" with "Alberta"
[perldigious]: I used to live at the top of a very steep hill stevieb, I can relate to the video. Literally used to have to build up momentum and try to force my vehicle to make it up the hill to park in my driveway properly... didn't always make it.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-12-06 16:32 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.