in reply to Re: HTML::Template-Displaying DB Records-Still struggling
in thread HTML::Template-Displaying DB Records

Here is how you examine a complex data structure:
use Data::Dumper; print Dumper $rows;
That will show you what's in it.

Honestly, I have never used the convenience functionns in DBI like selectall_arrayref, so I don't know if you are using it right. Why don't you try going one step lower and calling prepare, execute, and fetchall_arrayref separately?

Replies are listed 'Best First'.
Re: Re: Re: HTML::Template-Displaying DB Records-Still struggling
by thisisperl (Novice) on May 25, 2004 at 21:23 UTC
    Thanks. I tried Data::Dumper and here's the output:
    <br> use Data:: Dumper; <br> print Dumper $dbh; <i>###This displays $VAR1 = bless( {}, 'DBI::db' +); -does this mean DB connection was established? (do need an answer +here)</i> <br> print $rows; <i>###This displays ARRAY(0x1ed0ad8)</i> <br> print Dumper $rows; <i>### This displays $VAR1 = []; which means the a +rray reference is empty-but why?</i> <br>
    I also tried fetchrow_hashref():
    my $rows=[]; $sth = $dbh->prepare( $SQL ); $sth->execute(); push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); print Dumper $dbh; #Prints $VAR1 = bless( {}, 'DBI::db' ); print Dumper $sth;#Prints $VAR1 = bless( {}, 'DBI::st' ); print Dumper $rows; #Prints $VAR1 = [];
    Same problem. Surprisingly, if you look at the code in my previous posts, I used selectcol_arrayref successfully in the retrieveFormData function so the DB connection seems to be fine. What could possibly be wrong?
      First, I would chasnge that while $_ = $sth->fetchrow_hashref() into a simple for loop. It's just a little confusing right now, and hard to tell if there may be some strange scoping issue going on. Don't use $_ for this.

      Then I would break it down some more. Try running just this section of code in a separate script (after providing a $dbh of course).

      You should pass the RaiseError option to DBI, because you are not checking return values for errors here. You should also use bind variables. I'm not sure where you got the idea that bind variables don't work with LIKE queries. They work just fine, and will make your code more robust.