
FishMonger
Veteran
/ Moderator
Jun 18, 2009, 4:56 PM
Post #2 of 3
(5569 views)
|
Re: [GISX] Use dynamic driver based on ENV var
[In reply to]
|
Can't Post
|
|
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.
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)
|