Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Class::DBI connect info from file?

by jest (Pilgrim)
on Jan 21, 2004 at 22:15 UTC ( [id://323041]=note: print w/replies, xml ) Need Help??


in reply to Class::DBI connect info from file?

I keep my connection info in a config file, so I'll have something like library.site.conf that includes

DB_NAME = library DB_HOST = localhost DB_USER = username DB_PASS = password
Then, in my base DBI package, I have:
package MyDatabase::DBI; use base qw(Class::DBI::mysql); my %config; use Config::General; my $conf = new Config::General( -ConfigFile => '/usr/local/configfiles/library.site.conf', -InterPolateVars => 1 ); %config = $conf->getall; my $dsn = "DBI:mysql:host=$config{DB_HOST};database=$config{DB_NAME}"; my $db_user = $config{DB_USER}; my $db_pass = $config{DB_PASS}; __PACKAGE__->set_db('Main', $dsn, $db_user, $db_pass); # etc.

There are a ton of similar ways to do this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found