Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Stumped by disappearing $sth

by hesco (Deacon)
on May 25, 2009 at 04:53 UTC ( [id://765961]=perlquestion: print w/replies, xml ) Need Help??

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

This same $self->{'dbh'} is working in every other method of this module, but seems to have gone South on me in this code. It prepares a query and produces what looks to be a $sth. But when I execute the $sth, it returns 1, which has no ->fetchrow_hashref() method.

Any ideas would be appreciated.

my $sql = $self->{'cfg'}->param("sql.get_service_plans"); $self->log('The $service_plans query reads: ',$sql); my $sth = $self->{'dbh'}->prepare($sql) or die $self->{'dbh'}->errst +r; $self->log('It\'s $sth looks like this: ',$sth); my $service_plans = $sth->execute() or die $self->{'dbh'}->errstr;; $self->log('The $service_plans query looks like this: ',$service_pla +ns); while (my $plan = $service_plans->fetchrow_hashref()){ print Dumper($plan); }
And from the logs:

The $service_plans query reads: $VAR1 = 'SELECT svc_plan_id, plan_name, plan_image, plan_description, +plan_deposit, plan_monthly_fee, plan_prepaid_discount, plan_list_size +, plan_group_count FROM svc_plans WHERE plan_active ORDER BY plan_sor +t_order'; It's $sth looks like this: $VAR1 = bless( {}, 'DBI::st' ); The $service_plans query looks like this: $VAR1 = 1; Can't call method "fetchrow_hashref" without a package or object refer +ence at . . .
Thanks,

-- Hugh

UPDATE:

Thanks targetsmart, a second set of eyes got me past that one in a handful of minutes. Your help is appreciated. -- HE

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Stumped by disappearing $sth
by targetsmart (Curate) on May 25, 2009 at 05:01 UTC
    'execute' will return status, not the handle.
    try $sth->fetchrow_hashref()

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
      Thanks, mate. I think the sleep deprivation may be catching up with me. I had stared at that one for some time reading right past that.

      -- Hugh

      if( $lal && $lol ) { $life++; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found