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

Hi Monks
What sorts of things would cause a
Can't call method "bind_param" on an undefined value at nameofscript.p +l
I'm sure that I've initialised the relevant variable - its at the top of the script as
my $variable = " ";
and then later is assigned a proper value. I even print out the variable to check it has a value in it before invoking the SQL query that uses the variable.
Any useful tips/ suggestions as to what I should look for?

Replies are listed 'Best First'.
Re: get undefined error when trying to invoke SQL query in perl script
by derby (Abbot) on Oct 04, 2006 at 14:04 UTC

    Need more code. The problem isn't with the variable you're trying to bind but the variable invoking the bind_param call. The normal sequence of events is something like this:

    my $dbh = ....; my $sth = $dbh->prepare( "SELECT fld from tab where fld = ?" ); $sth->bind_param(1, "val"); $sth->execute;
    So from your error message above, I would assume your statement handle is bad.

    -derby
Re: get undefined error when trying to invoke SQL query in perl script
by shmem (Chancellor) on Oct 04, 2006 at 14:05 UTC
    Look for a line reading like
    $variable->bind_param()

    in your code. $variable seems to be undefined.

    If you had provided your script, I could be more precise. See How (Not) To Ask A Question.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}