mp has asked for the wisdom of the Perl Monks concerning the following question:
The problem with my current solution is that
Example of flawed code is below. MyProject::Dbh "isa" Apache::Singleton::Process that makes a connection using the correct DSN, user, and password using DBI. Apache::DBI is used as well to make the connections persistent, but that is beside the point.
My question, then, what is a better way to manage the connection? Should it be in instance data rather than class data? Should it be set in each method that uses the database (ugly)? I am pleased almost all features of the current approach except for its flaw of never calling connect after initialization (which in Apache::DBI would take care of returning a good connection).use MyProject::Dbh; my $dbh = MyProject::Dbh->instance->dbh; sub method1 { $dbh->do("... query goes here ..."); } sub method2 { my $sth = $dbh->prepare("... another query ..."); $sth->prepare; #... } } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem managing persistent database connections in modules
by LanceDeeply (Chaplain) on Jul 25, 2002 at 20:54 UTC | |
by mp (Deacon) on Jul 26, 2002 at 00:35 UTC | |
|
Re: Problem managing persistent database connections in modules
by mfriedman (Monk) on Jul 25, 2002 at 20:17 UTC | |
by mp (Deacon) on Jul 26, 2002 at 00:24 UTC | |
by mfriedman (Monk) on Jul 29, 2002 at 23:24 UTC | |
|
Re: Problem managing persistent database connections in modules
by Ryszard (Priest) on Jul 25, 2002 at 18:24 UTC |