Jaap has asked for the wisdom of the Perl Monks concerning the following question:
But if i place this in a subroutine, the sub must return the object $sth or a copy of it. I am afraid that returning $sth after the finish and disconnect will not work. Making a reference to $sth won't do much good either since it's contents will probably be gone after the finish().$dbh = DBI->connect("DBI:mysql:database=db;host=host", $user, $pass); $dbquery = 'select * from table'; $sth = $dbh->prepare($dbquery); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { print $ref->{'id'}; } $sth->finish(); $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copy an object
by perlplexer (Hermit) on Apr 25, 2002 at 20:52 UTC | |
by cLive ;-) (Prior) on Apr 26, 2002 at 07:13 UTC | |
|
Re: Copy an object
by VSarkiss (Monsignor) on Apr 25, 2002 at 20:23 UTC | |
|
Re: Copy an object
by Super Monkey (Beadle) on Apr 25, 2002 at 22:05 UTC | |
|
Re: Copy an object
by cLive ;-) (Prior) on Apr 26, 2002 at 07:25 UTC | |
|
Re: Copy an object
by Jaap (Curate) on Apr 26, 2002 at 08:09 UTC |