in reply to Problem creating a singleton wrapper around DBI
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 ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem creating a singleton wrapper around DBI
by eric256 (Parson) on Aug 23, 2005 at 20:37 UTC |