Hey guys,
I'm wondering what's the best way to design a database-backed module
which works completely on its own as well as within mod_perl (mp1).
The module should make a database connection during object initialization
(new). This connection should then be used by all methods which want to
Tobias Kremer wrote:
That's easy under standalone conditions (connect within new,
store the dbh in $self-{_dbh} and use that in other methods).
I don't recommend doing that. Better to use DBI-connect_cached in most
cases. It will actually check to see if your connection is still good
Zitat von Perrin Harkins [EMAIL PROTECTED]:
You need to separate managing your database connections from caching
this data. They are not related, and there's no reason to do both in
one class. Either just call connect_cached all the time (it uses
Apache::DBI when it finds it loaded), or
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,
John ORourke wrote:
It does make a separate DB connection in each apache process but
I think trying to share 1 DB connection between httpd's is probably
going to cost more than it gains.
It's not actually possible to share a connection between processes
unless your database library
Zitat von Perrin Harkins [EMAIL PROTECTED]:
Create a new instance of the mod_perl handler module during startup and
refer to that for the handlers (code below).
This module would then cache DB connections and provide a method for
'create or fetch current DB connection'.
Perrin Harkins wrote:
Create a new instance of the mod_perl handler module during startup
and refer to that for the handlers (code below).
This module would then cache DB connections and provide a method for
'create or fetch current DB connection'.
DBI-connect_cached will do all of this