hi martin
    I'm not a expert but here what 've done

package MyConn;

use strict;


use vars qw( $dbh );   # cached connection, one  by apache child

my $dsn = "dbi:postgresql:dbname=mydb";

my $user = "myuser";
my $password = "mypass";

sub getCached {
  my $pkg = shift;
  if ( $dbh ){
    if ( $dbh->ping() ){
      return $dbh;
    }
  }
  $dbh = DBI->connect($dsn,$user, $password, { AutoCommit => 1, RaiseError
=> 1 } )||
    die "ERROR NO_CONNECTION_TO_POSTMASTER\n";
  return $dbh;
}

It sound like Apache::DBI.

When I need a cached connection in another package, I call
MyConn->getCached()

$dbh = MyConn->getCached();

Then I should implement:

sub get { #uncached connection ( for transaction...)
    my $dbh2 = DBI->connect($dsn,$user, $password, { AutoCommit => 1,
RaiseError => 1 } )||
    die "ERROR NO_CONNECTION_TO_POSTMASTER\n";
    return $dbh2;
}

sub END { # To close cleanly...
    if ( $dbh && $dbh->ping() ){
     $dbh->disconnect();
    }
}

but I working on this ...

Hope its help




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to