[cgiapp] Lazy DBI

Mark Knoop mark at rawcane.net
Tue Feb 19 05:02:13 EST 2008


In case it is of interest I have solved the problem like this.

package GSystem::Common::DBH;

use strict;
use warnings;
use Log::Log4perl qw(get_logger);
use DBI;

our $dbh = undef;

sub dbh {

 my $log = get_logger('GSystem::Common::DBH');

 my $dbusr = "user";
 my $dbpwd = "pwd";
 my $dsn = "GSystem";

 $dbh = DBI->connect("DBI:ODBC:$dsn", $dbusr, $dbpwd, {RaiseError => 0, 
PrintError => 0})  || $log->logdie ("Could not connect to database")
  unless defined $dbh;

    return $dbh;
}

1;

So when I want a dbh I use

my $dbh = GSystem::Common::DBH::dbh;

and I (think) I either get a new or existing dbh.

I would be interested to know of any flaws in my logic...

Mark




More information about the cgiapp mailing list