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

Error with the bind_param

by Win (Novice)
on Apr 04, 2007 at 11:10 UTC ( #608251=perlquestion: print w/ replies, xml ) Need Help??
Win has asked for the wisdom of the Perl Monks concerning the following question:

I get an error with the bind_param when I run the following. I've tried to debug with various alterations. Please can a kind monk guide me.
$dbh->prepare($Command_B); my $count = 1; my $sthB_A; foreach (@CHOICE_B[1 .. $elements_in_array_B]){ $sthB_A->bind_param($count, $_); $count++; } $sthB_A = $dbh->do($Command_B) or die "Couldn't do query: ".$dbh->err +str;
Error is 'Can't call method bind_parm on an undefined value'.

Comment on Error with the bind_param
Download Code
Replies are listed 'Best First'.
Re: Error with the bind_param
by Ovid (Cardinal) on Apr 04, 2007 at 11:13 UTC

    That's because $sthB_A is undefined. The do() method will take a prepared statement, though.

    my $sthB_A = $dbh->prepare($Command_B); my $count = 1; foreach (@CHOICE_B[1 .. $elements_in_array_B]){ $sthB_A->bind_param($count, $_); $count++; } my $result = $dbh->do($sthB_A) or die "Couldn't do query: ".$dbh->err +str;


    New address of my CGI Course.

Re: Error with the bind_param
by roboticus (Chancellor) on Apr 04, 2007 at 11:14 UTC


    You need to actually have a statement handle to execute bind_param on it. You're trying to do your binding before you create it. Something like painting a house before you build it....


Re: Error with the bind_param
by davidrw (Prior) on Apr 04, 2007 at 11:53 UTC
    are you _sure_ @CHOICE_B[1 .. $elements_in_array_B] is what you want? Seems like it should be just @CHOICE_B ...

    You can also simplify the whole thing (see DBI docs) into one line:
    my $rv = $dbh->do($Command_B, {}, @CHOICE_B) or die "Couldn't do query +: ".$dbh->errstr;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://608251]
Approved by Ovid
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-10-09 04:36 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (233 votes), past polls