Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: basic dbi question

by wallisds (Beadle)
on Dec 01, 2010 at 21:07 UTC ( #874764=note: print w/replies, xml ) Need Help??


in reply to Re^2: basic dbi question
in thread basic dbi question

Are you looking for a way to shorten the method to get your result out of the query? Like a way to replace execute, prepare, fetch?
If so, check out CPAN on DBI:
http://search.cpan.org/~timb/DBI-1.615/DBI.pm

Here are some my favorites... For one row of results I usually like to use:

my ($col1, $col2, $col3) = $dbh->selectrow_array($query);

For multiple rows I like the array ref methods. Here is one right from CPAN (http://search.cpan.org/~timb/DBI-1.615/DBI.pm#selectall_arrayref)

my $emps = $dbh->selectall_arrayref( "SELECT ename FROM emp ORDER BY ename", { Slice => {} } );

To then access your result you can use this loop

foreach my $emp ( @$emps ) { print "Employee: $emp->{ename}\n"; }

There is a lot of information on DBI in CPAN.

Dawn

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-01-29 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?