Re: DBIx::DBH - Perl extension for simplifying database connections

From: Ron Savage (ron_at_savage.net.au)
Date: 12/01/04


To: Perl - DBI users <dbi-users@perl.org>
Date: Thu, 2 Dec 2004 08:34:20 +1100

On Wed, 1 Dec 2004 18:39:00 +0000, Tim Bunce wrote:

H Tim

> need a better understanding of the underlying issues. More real-
> world examples would help.

Here's a real world example of how I do things, although I am in no way convinced that such a module as we are discussing is needed...

The problem:
I run identical code on my local PC and on my web host's PC interstate.

The solution:
To simplify connexion matters, I just change one parameter to the constructor, from
Class -> new(site => 'local') to Class -> new(site => 'remote'), and use that to index
into a hash to get the connexion parameters. So, with $$self{'_site'} populated via new()
and $$self{'_dsn'} stored within the class, like:
                _dsn =>
                {
                        local => ['dbi:mysql:db_name1:127.0.0.1', 'username1', 'password1'],
                        remote => ['dbi:mysql:db_name2:dbhost.quadrahosting.com.au', 'username2', 'password2'],
                },
        _site => '', # Must be one of local | remote. Validated in new().
        _other_stuff...
I can now connect with something like DBI -> connect(@{$$self{'_dsn'}{$$self{'_site'} } }, %attr);

Simple!

PS
I've found quadrahosting very cooperative. They are a US company with an Australian office, and vastly cheaper that their Australian competitors (but let's not start a discussion about that in this thread, please).
See the mod_perl web site for hosting companies:
http://perl.apache.org/help/isps.html

-- 
Cheers
Ron Savage, ron@savage.net.au on 2/12/2004
http://savage.net.au/index.html