in reply to Testing & Databases
There are as many ways of skinning that cat as there are folks trying to skin it. Here are some of the aproaches I've seen without passing judgement on any of them.
The above ripped from some code I'm maintaining. The actual values changed to protect the guilty.# .bashrc sniglet export DBHOST="mytestdbhost.mydomain.tld" export DBDB="mytestdb" export DBUSER="user" export DBPASSWORD="SeCrEt" export DBDRIVER="mysql" ------- 8<snip! 8<-------------------------- # in some perl code, far far away use DBI; my $dbhost = $ENV{'DBHOST'}; my $dbname = $ENV{'DBDB'}; my $dbuser = $ENV{'DBUSER'}; my $dbpassword = $ENV{'DBPASSWORD'}; my $dbdriver = $ENV{'DBDRIVER'}; my $DSN=sprintf("DBI:%s:host=%s:database=%s", $dbdriver,$dbhost,$dbnaem); my $dbh=DBI->connect($DSN,$dbuser,$dbpassword) or die DBI->errstr; ... etc....
The other method I've seen (and used myself) is to create your own module that encapsulates your database access configuration. The one I use over and over again I call (oddly enough) DbConfig.
use DBConfig; use DBI; my $dbh=DBI->connect(DBConfig::DSH,DBConfig::User,DBConfig::Password) +or die $DBI::errstr;
When I install DBConfig on my production boxes I make the appropriate changes to the module. Otherwise the code is identical.
As always in Perl TIMTOWTDI!
| Peter L. Berghold -- Unix Professional Peter at Berghold dot Net | |
| Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice. | |
|
|---|