Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Passing Database handles to other modules.

by arturo (Vicar)
on May 06, 2003 at 14:14 UTC ( #255889=note: print w/replies, xml ) Need Help??

in reply to Passing Database handles to other modules.

Given a pooling mechanism, my inclination is to let each bit of code that needs a DB handle just grab it from the pool (and you can simplify this by creating a connector that just returns a connection for you, instead of having to manually call DBI->connect all the time). The one exception to this model would be if you have a backend that supports transactions1, so that the session associated with a given handle really matters, in which case, of course the thing to do is simply pass the handle around as you would any other object, as has already been pointed out.

1 I suppose it might also apply if your DBMS has something equivalent to MySQL's last_insert_id, as that may be session-and-thus-connection-dependent as well.

If not P, what? Q maybe?
"Sidney Morgenbesser"

Replies are listed 'Best First'.
Re: Re: Passing Database handles to other modules.
by perrin (Chancellor) on May 06, 2003 at 14:21 UTC
    Apache::DBI will give you the same handle every time if you connect with the same parameters. Grabbing it from the "pool" is no different from passing it, since there is actually only one database connection per process when you keep using the same connection string. Apache::DBI provides persistent connections, not pooled ones.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2023-03-24 19:56 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.