Re: Syntax errors across multiple virtual hosts with separate codebase
Chris Winters <[EMAIL PROTECTED]> wrote: > 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 ' to > start using a different database. FWIW, MySQL is quite happy performing queries on foreign databases through DBI; I've needed to do this to perform queries that span tables on multiple databases. Not sure of the performance overhead, but if you fully qualify your fields (as in db.table.field) it shouldn't matter what database your handle is actually opened on. Pete
Re: Syntax errors across multiple virtual hosts with separate codebase
Chris Winters wrote: [EMAIL PROTECTED]">* 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 hostsAnother 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 centrallocation then passed around, or in each handler as you need it), butin MySQL (as with other databases) you can execute a 'use ' tostart using a different database.So your definition can be the same for all virtual hosts but you candefine a variable via PerlSetVar or in a configuration file that hasthe database name. When you ask for a database handle you can thencreate it using a common database name (e.g, 'mysql') and thenexecute the 'use ' statement: Thanks a bunch - I never thought about using "use " in a mod_perl/DBI context. It's obvious when you know it ;-). -- Med venlig hilsen-ToemTommy Davis, Technical DirectorAdapt A/S, Havnegade 41, 2. sal, 1058 København KTel +45 3341 1050, Fax +45 3341 1069, http://www.adapt.dk/
Re: Syntax errors across multiple virtual hosts with separate codebase
G.W. Haywood wrote: [EMAIL PROTECTED]"> 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.Our problem is that a syntax-error in a program used on only one virutal host, causes an "internal server error" across all virtual hosts.I suspect it's not possible to avoid this, but I would like to be sure. Can anyone confirm this? Nope. I suspect your code isn't as separate as you think it is. I'm quite sure the they are separate, but I'll try some simple test-scenarios tonight to double-check. -- Med venlig hilsen -Toem Tommy Davis, Technical Director Adapt A/S, Havnegade 41, 2. sal, 1058 København K Tel +45 3341 1050, Fax +45 3341 1069, http://www.adapt.dk/
Re: Syntax errors across multiple virtual hosts with separate codebase
Chris Winters ([EMAIL PROTECTED]) said something to this effect on 05/02/2001: > package MyServer::DB; > > use strict; > use DBI; > > my $DB_USER = ''; > my $DB_PASS = ''; > > 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; > } I wrote something like this once: ### package MyDB; use DBI; use base 'DBI::db'; { my $dsn; sub import { my $class = shift; while (@_) { my ($n, $v) = splice @_, 0, 2; $dsn->{$n} = $v; } } sub new { my $class = shift; my $dbh = DBI->connect( sprintf('dbi:mysql:%s:%s', @{$dsn}{'database','hostname'}), $dsn->{'username'}, $dsn->{'password'}, { RaiseError => 1 }); bless $dbh, $class; } } sub DESTROY { shift->disconnect } 1; ### (With a little sanity checking inside &import to make sure all the required entries at least have reasonable defaults). Which gets used like so: #!/usr/bin/perl use MyDB username => 'foo', password => 'bar'; my $db = MyDB->new; It makes all the database stuff a little cleaner, and a little better encapsulated. (darren) -- Pessimests are right more often, but optimists are happy more often.
Re: Syntax errors across multiple virtual hosts with separate codebase
* 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 ' 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 ' statement: package MyServer::DB; use strict; use DBI; my $DB_USER = ''; my $DB_PASS = ''; 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.
Re: Syntax errors across multiple virtual hosts with separate codebase
Hi there, On Wed, 2 May 2001, Tommy Davis wrote: > 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. > > Our problem is that a syntax-error in a program used on only one virutal > host, causes an "internal server error" across all virtual hosts. > I suspect it's not possible to avoid this, but I would like to be sure. > Can anyone confirm this? Nope. I suspect your code isn't as separate as you think it is. 73, Ged.
Syntax errors across multiple virtual hosts with separate codebase
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. Our problem is that a syntax-error in a program used on only one virutal host, causes an "internal server error" across all virtual hosts. I suspect it's not possible to avoid this, but I would like to be sure. Can anyone confirm this? 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 would be very interested to hear how others have solved this problem ( without buying more servers ;-). -- Med venlig hilsen -Toem