Is this the sort of thing you're looking for?# untested! just off top of head my $db = 'DBI:mysql:database=db;host=host'; my $user = '...'; my $pass = '...'; my $result = db_query('select * from table'); my $dbh; sub db_query { my $sql = $_[0]; $dbh = DBI->connect_cached($db, $user, $pass); my $sth = $dbh->prepare($sql); $sth->execute(); my $result_hashref = {}; while (my $ref = $sth->fetchrow_hashref()) { $result_hashref->{ $ref->{'id'} } = $ref; } $sth->finish(); return $result_hashref; } sub DESTROY { if (defined $dbh) { $dbh->disconnect(); } }
.02
cLive ;-)
In reply to Re: Copy an object
by cLive ;-)
in thread Copy an object
by Jaap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |