CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI: Re: [GISX] Use dynamic driver based on ENV var: Edit Log



FishMonger
Veteran / Moderator

Jun 18, 2009, 4:56 PM


Views: 2552
Re: [GISX] Use dynamic driver based on ENV var

Yes, you can use an environment variable, but the use statement happens at compile time so you need to do the my $db_driver = assignment at compile time as well. However, using this approach, you'd also need to modify the connect statement.

Actually, there is no need to explicitly "use" the DBD module because the DBI module does that for you via a require statement where the needed DBD module is based on the connect statement.

This is how I'd do it.

Code
my $dbd = $ENV{DBI_DRIVER};  # the value is either 'Informix' or 'Oracle' 

my $dbh = DBI->connect("DBI:$dbd:db", 'user', 'password',
{ RaiseError => 1 } )
or die "Error:" . DBI->errstr . "\n";



(This post was edited by FishMonger on Jun 18, 2009, 5:02 PM)


Edit Log:
Post edited by FishMonger (Veteran) on Jun 18, 2009, 4:57 PM
Post edited by FishMonger (Veteran) on Jun 18, 2009, 4:57 PM
Post edited by FishMonger (Veteran) on Jun 18, 2009, 4:59 PM
Post edited by FishMonger (Veteran) on Jun 18, 2009, 4:59 PM
Post edited by FishMonger (Veteran) on Jun 18, 2009, 5:02 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives