dbi question
Stray Toaster
mwk at stray-toaster.co.uk
Sun May 13 07:19:04 CDT 2001
Yo!
I would ask this in work tomorrow, but there is something I want to get
finished today, so thought I would ask for some help.And encourage the
use of this list for such things!
I have a module doing things. Diary entry sort of things, but that is
irrelevant. Inside the module I get my own database handle, like so:
sub dbh {
my $self = shift;
require DBI;
my @drivers = DBI->available_drivers;
my $dbh = DBI->connect("DBI:mysql:mwk", "mwk", "mwk123",
{ PrintError => 0,
}
);
return $dbh
}
Cool. Or so I thought. So here is the issue.
I have get/create methods, for entering data and retrieving it.
Obviously enough. But the thing is, how do I do the disconnect? It seems
messy to put inside (for example) the get method:
my $dbh = $self->dbh;
my @results = @{ $dbh->selectall_arrayref($details, undef,
$self->date) };
$dbh->disconnect;
and then have to do the same thing in the set method. (And anywhere else
I use a handle.) That is, the explicit call a handle, then explicitly
destroy it.(I don't mind the making, it is the disconnect that is
bugging me.)
So how do I avoid all that then? I am sure I am missing the obvious
here...........
m.
--
"I don't see much sense in that" said Rabbit
"No" said Pooh, humbly, "there's isn't. But
there was going to be when I began. It is just
something happened to it on the way."
More information about the Belfast-pm
mailing list