Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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
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;

    Cheers,
    Ovid

    New address of my CGI Course.

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

    >Sigh<

    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....

    ...roboticus

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-08-29 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls