Re: ASP setup using common set of C::DBI modules

[prev] [thread] [next] [Date index for 2004/07/28]

From: Michael Graham
Subject: Re: ASP setup using common set of C::DBI modules
Date: 20:33 on 28 Jul 2004
Quoting jason scott gessner <jason@xxxxxxxx.xxx>:
> I have a set of classes all under a single namespace for my app.  These
> modules are used by several mod_perl/mason applications living on
> multiple VHOSTS on the same physical server (for now).  I have some
> wrapper functions in my C::DBI wrapper class that let me choose from a
> list of database instances on multiple servers.  That is super handy
> and works fine.  However, what happens is that mod_perl caches that
> class once for all the vhosts.  So if i set an instance in one host, it
> clobbers the other hosts.

I just went through a similar process.  The usual way to handle this is to
override db_Main in your Class::DBI classes to return a dbh based on some
runtime info.

I use PerlSetEnv in each virtual host to set an environment variable.

Then I have a base class for all my Class::DBI classes.  In this class I define
the method db_Main, which retrieves the database connection info from the
configuration system.  The configuration system is sensitive to the environment
variable and returns the appropriate credentials.  db_Main then passes these
credentials to DBI->connect_cached to get a dbh, and returns this.

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;
    }


Michael


--
Michael Graham
magog@xxxxxxxx.xxx

ASP setup using common set of C::DBI modules
jason scott gessner 19:43 on 28 Jul 2004

Re: ASP setup using common set of C::DBI modules
Michael Graham 20:33 on 28 Jul 2004

Re: ASP setup using common set of C::DBI modules
Michael Graham 22:01 on 28 Jul 2004

Re: ASP setup using common set of C::DBI modules
jason scott gessner 20:24 on 29 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52