[Dbix-class] Problem using DBIC in a Catalyst/mod_perl environment with multiple virtual hosts

Brandon Black blblack at gmail.com
Tue Aug 22 17:01:58 CEST 2006


On 8/22/06, Andreas Dembach <ad at dg-i.net> wrote:
>
>
> Hello list,
>
> we have the following situation:
>
> - we are migrating mod_perl application to Catalyst under mod_perl2 and
> use DBIC as persistence layer.
> - the apache server hosts two (in fact even more) virtual hosts with the
> same application but different configurations (e.g. one for test and one
> for production).
> - beneath other configuration items, like template-root we want the
> different virtual hosts to use different database connections.
>
> Problem:
>
> As far as I can tell from the source code, DBIx::Class::Storage::DBI
> caches the database handle in '_dbh' which results in always using the
> first database handle that inititated a connection. So we end up having
> the configured $dbh of whatever virtual host  is called first within a
> newly created Apache process.
>
> Question:
>
> Is this a design decision to support only one DB connection per process
> or is this a little bug that could be fixed by caching the dbh with some
> additional meta info (e.g. the connection parameters à la
> DBI->connect_cached)?


Skipping the Catalyst part of things and just focusing on DBIx::Class: This
should be a non-issue as long as you're using schema objects rather than
schema classes, which is the preferred and recommended way to go about
things.

Are you directly accessing the schema class?  Are you using
Catalyst::Model::DBIC::Schema?  Can you paste/post your Schema and Model
files, so we can see exactly how you're connecting things?  I *think*
C::M::DBIC::Schema handles this case correctly, but of course there could be
a bug or thinko of some kind.

-- Brandon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060822/130cf537/attachment.htm 


More information about the Dbix-class mailing list