Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Passing DBI resultset to function

by roboticus (Chancellor)
on Dec 15, 2009 at 20:03 UTC ( [id://812925]=note: print w/replies, xml ) Need Help??


in reply to Passing DBI resultset to function

DreamT:

Here's an untested example of how you go about passing a statement handle (resultset) to a subroutine.

my $sth = $dbh->prepare("MY SQL QUERY"); $sth->execute(); SimpleResultsDump($sth); sub SimpleResultsDump { my $SH = shift; my $cnt=0; while (my $hr = $SH->fetchrow_hashref()) { print ("-" x 40), " record: ", ++$cnt, "\n"; for my $k (sort keys %$hr) { my $v = "'$$hr{$k}'" // 'null'; print "Field $k holds: $v\n"; } } }

...roboticus

Error checking left as an exercise for the reader!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://812925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-05-22 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found