Tobias Kremer wrote:
Ok, got that! But how does the class get its database handle to operate on?

One of these ways:

my $dbh = DBI->connect_cached(...);
my $dbh = My::Database->get_dbh();

You do that every time you need one.

sub new {
  ... $self->{_dbh} = My::Database->new()->dbh(); ...
}

No, stop trying to store the database handle in this object. Keep it in one place where one chunk of code can manage it.

One solution that just popped into my mind is changing My::Database's "dbh"
method so that it always connects using connect_cached instead of doing it
once during creation of My::Database. Would that be a feasible solution?

Yes. You could also have it cache the connection in $r->pnotes if running under mod_perl and finding a request. (How you do that varies by which mod_perl you have.)

- Perrin

Reply via email to