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

DBD::CSV - Not Fetching Rows

by perlmannan (Initiate)
on Feb 18, 2009 at 10:45 UTC ( [id://744712]=perlquestion: print w/replies, xml ) Need Help??

perlmannan has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys

I am using two CSV files as DB with DBD::CSV Driver.

I used the following code to run a Select query.
------------------------- $dbh = DBI->connect("DBI:CSV:f_dir=/amd/homes/banni/PI/DB") or die "Cannot connect: " . $DBI::errstr; $table='etl'; $dbh->{'RaiseError'} = 1; $@ = ''; eval { $query = "SELECT playercode,playername FROM $table"; $sth = $dbh->prepare($query); $sth->execute(); $sth->execute(); while ($sth->fetchrow_arrayref()) { print("Found result row: @$_\n"); } $fields = $sth->{NUM_OF_FIELDS}; print "Fields = $fields\n"; $sth->finish(); }; ----------------------
Assume the table(file 'etl') contains the following data
playercode,playername 1,Apple/iPod/iPhone 2,Leap Frog/Leapster 3,Microsoft Zune 4,Mylo
I am able to fetch the number of fields here. But while i use $sth->fetchrow_arrayref, the rows are not fetched. Tried using fetchrow_array and fetch functions too. And the sad thing I didn't any error messages too:(

Please help me to solve this problem

Thanks in advance

Replies are listed 'Best First'.
Re: DBD::CSV - Not Fetching Rows
by romandas (Pilgrim) on Feb 18, 2009 at 13:42 UTC
Re: DBD::CSV - Not Fetching Rows
by kennethk (Abbot) on Feb 18, 2009 at 14:36 UTC
    At no point do you store the value returned by $sth->fetchrow_arrayref() - your code can be modified to work by changing your code to read while ($_ = $sth->fetchrow_arrayref()). Please read DBI for proper syntax and perlvar for proper usage of $_. And as romandas said, please be more contentious formatting your posts.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found