Re: ASP setup using common set of C::DBI modules
[prev]
[thread]
[next]
[Date index for 2004/08/01]
On Thu, Jul 29, 2004 at 03:24:34PM -0500, jason scott gessner wrote:
> Hi All.
>
> I tried this out and it kinda works.
>
> Basically, it workds if i do this at the top of each of my autohandlers:
> my $dbh = PS::DBI::dbh();
>
> Otherwise, db_Main() is being cached somewhere and never going out of
> scope, leading to some requests going to another vhost's database.
> This is a real bummer. Any thoughts?
Adding the vhost name to the connect_cached() attribute hash would
ensure each vhost gets separate connections. A dummy private attribute
would work for that:
private_vhost_name => $vhost_name
Tim.
> On Jul 28, 2004, at 3:48 PM, Tony Bowden wrote:
>
> >On Wed, Jul 28, 2004 at 04:33:38PM -0400, Michael Graham wrote:
> >>The code looks something like this:
> >> package My::Class::DBI::Base;
> >> use base 'Class::DBI';
> >> use CLASS;
> >> use My::Config;
> >> use DBI;
> >>
> >> sub db_Main {
> >> my ($dsn, $user, $pass) =
> >>My::Config->get_config('dbi_connection_info');
> >> my %attr = CLASS->_default_attributes();
> >> my $dbh = DBI->connect_cached($dsn, $user, $pass, \%attr);
> >>
> >> return $dbh;
> >> }
> >
> >One slight problem with this is your use of CLASS. This means that
> >subclasses can't provide their own default attributes.
> >
> >You'd be better off here with:
> >
> > sub db_Main {
> > my $class = shift;
> > my ($dsn, $user, $pass) =
> >My::Config->get_config('dbi_connection_info');
> > my %attr = $class->_default_attributes();
> > return DBI->connect_cached($dsn, $user, $pass, \%attr);
> > }
> >
> >Tony
> >
>