* Tommy Davis ([EMAIL PROTECTED]) [010502 04:11]:
> We use a server-setup with a mod_perl enabled backend server. The server
> only runs mod_perl and mySQL for about 5 virtual hosts.
>
> ...
>
> Another problem is that the solutions uses diffferent databases. That
> means we end up with 5 ttimes as many open db handles as we have
> mod_perl processes.
> We have worked around this by merging all databases into a single one,
> prefixing the table_names with the former db-names and using a simple
> abstraction layer to access the database.
I'm not sure how you create your database handles (in a central
location then passed around, or in each handler as you need it), but
in MySQL (as with other databases) you can execute a 'use <dbname>' to
start using a different database.
So your definition can be the same for all virtual hosts but you can
define a variable via PerlSetVar or in a configuration file that has
the database name. When you ask for a database handle you can then
create it using a common database name (e.g, 'mysql') and then
execute the 'use <dbname>' statement:
package MyServer::DB;
use strict;
use DBI;
my $DB_USER = 'xxxx';
my $DB_PASS = 'yyyy';
sub connect {
my ( $class, $dbname ) = @_;
my $dbh = DBI->connect( 'DBI:mysql:mysql', $DB_USER, $DB_PASS,
{ RaiseError => 1 } )
|| die "$DBI::errstr\n";
$dbh->do( "use $dbname" ) if ( $dbname );
return $dbh;
}
We do something like this in OpenInteract and, for MySQL at least, it
works fine.
Chris
--
Chris Winters ([EMAIL PROTECTED])
Building enterprise-capable snack solutions since 1988.