Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-01-24 10:18 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (257 votes). Check out past polls.