in reply to Re: Copy an object
in thread Copy an object
This works for me and lets me forget about the disconnect.# connect my $dbh = DBI->connect_cached(...) # then add sub DESTROY { if (defined $dbh) { $dbh->disconnect(); } }
The connect_cached only reconnects if cached connection doesn't exist. So you can safely put a connect_cached before a query if you're unsure whether you're connected without the performance hit of connecting/disconnecting all the time. docs here
Putting the disconnect in the DESTROY sub cleanly disconnects when the script exits - assuming, of course, that it will still be in scope :)
AFAIK! No-one has told me otherwise, anyway :)
.02
cLive ;-)
|
|---|