Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Seeking efficient and safe way to store database connection information

by valdez (Monsignor)
on Jul 26, 2004 at 22:28 UTC ( [id://377602]=note: print w/replies, xml ) Need Help??


in reply to Seeking efficient and safe way to store database connection information

There are several options; DBIx::Password is one of them, but I prefer to reinvent wheels and use an hand-made configuration singleton. I keep all the configurable values in a file readable by Config::General and limited by Class::Singleton:

#configuration file <system> dsn dbi:Oracle:dbname username dbuser password dbpwd <environment> ORACLE_HOME /ora92/product/9.2.1.0 </environment> </system>
Values are accessible using paths inside configuration file; for example, the following code is used to connect to an Oracle database:
my $conf = Configuration::Singleton->instance; my $address = $conf->value('system/dsn'); my $user = $conf->value('system/username'); my $pwd = $conf->value('system/password'); my $environment = $conf->value('system/environment'); while ( my ($variable, $value) = each %$environment ) { $ENV{ uc($variable) } = $value; } my $dbh = DBI->connect( $address, $user, $pwd, { RaiseError => 1, AutoCommit => 0 } ) or die "$DBI::errstr"; $dbh->{FetchHashKeyName} = 'NAME_lc';

The summary is: use some sort of configuration method. BTW, if you are using MySQL please note that it accepts the name of a configuration file in the connect string, see this trick told to me by gmax for a useful example.
Remeber to keep your configuration files out of the document root and restrict access to them.

HTH, Valerio

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377602]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-23 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found