As an alternative to caching the DBI connection yourself - get DBI to do it with connect_cached. This has the additional advantage of reconnecting if the old database handle has been disconnected or a ping fails.
sub new { # get necessary config info my $dbuser = conf::SiteConfig::get_conf ( 'dbuser' ); my $dbpass = conf::SiteConfig::get_conf ( 'dbpass' ); my $dbname = conf::SiteConfig::get_conf ( 'dbname' ); my $dbserv = conf::SiteConfig::get_conf ( 'dbserv' ); # Build up DBI connection string. my $datasource = 'dbi:mysql:'.$dbname; $datasource .= "\;host=$dbserv" if ( $dbserv ); # Connect return DBI->connect_cached( $datasource, $dbuser, $dbpass ); }
In reply to Re: Problem creating a singleton wrapper around DBI
by adrianh
in thread Problem creating a singleton wrapper around DBI
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |