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

my script was working perfectly all day, and i started fixing the aesthetics, and broke it!!

it's throwing the following error:

bind_columns called with 2 refs when 3 needed. at /usr/local/lib/perl5 +/site_perl/5.8.7/mach/DBI.pm line 1794.

i have 3 queries in the code, one pulls 3 fields, one pulls 4, and the last, 5. the one with 3 looks like:

my $sql = "SELECT UID, MONTHNAME(PostDate), YEAR(PostDate) FROM news O +RDER BY PostDate DESC"; my $sth = $dbh->prepare($sql) || die "Error preparing: $DBI::errstr"; $sth->execute || die "Error executing: $DBI::errstr"; $rv = $sth->bind_columns($UIDholder, $indexmonths, $indexyears);

the thing is that everything was working perfectly just an hour ago!!! and i haven't made any changes to the queries..

anyone know where i need to look to solve this one?

Replies are listed 'Best First'.
Re: bind_columns error
by runrig (Abbot) on Jun 29, 2006 at 22:08 UTC
    Actually provide a list of references:
    $rv = $sth->bind_columns( \($UIDholder, $indexmonths, $indexyears) );
    Or don't declare them at the top, just declare them during the call:
    $rv = $sth->bind_columns( \my ($UIDholder, $indexmonths, $indexyears) +);
Re: bind_columns error
by shmem (Chancellor) on Jun 29, 2006 at 21:48 UTC
    "If it ain't broken, don't fix it" as the saying goes...

    Are you shure that ($UIDholder, $indexmonths, $indexyears) are all references?

    --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}
      i declared them all at the top with use vars:
      use vars qw/ %in $dbh $sql $sth $UIDholder $indexmonths $indexyears @U +IDarray @montharray @distinctmontharray @yeararray @distinctyeararray + $q $rv $postmonth $postyear $monthnumber $postby $title $teaser @AoT +itle @AoTeaser $content $postdate/;

      isn't that enuf?

        No. Declaring them makes them suitable for use, but only if they are assigned something, they hold something: a scalar, reference, whatever. The error message tells you of not being enough references at some line, so you should check if the variables in question in fact hold references at that point. This can be done with the operator ref.

        --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}
Re: bind_columns error
by chargrill (Parson) on Jun 30, 2006 at 16:52 UTC

    Am I missing something?

    Where are $UIDholder, $indexmonths, $indesxmonths, $indexyears defined?

    Why are you calling bind_columns on a statement handle without placeholders?

    Normally, I see things like this:

    my $sql = 'insert into news values ( ?, ?, ? )'; ... $sth->bind_columns( $placeholder, $filler, $variables );

    I don't recall the semantics, but something similar ought to work with placeholders in a select statement. The docs would probably help confirm.

    Update: Ugh, you're right, runrig. I suppose I should've checked the docs myself instead of making an assumption based on faulty memory.

    For those still reading, ignore the above text :)



    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
      Where are $UIDholder, $indexmonths, $indesxmonths, $indexyears defined?
      The OP says in a later post that they are defined at the top of the program.
      Why are you calling bind_columns on a statement handle without placeholders?
      bind_columns() binds the select columns to variables, and affects where the data goes during fetch(). You are thinking of bind_params(), which binds placeholders and is called before execute(), and you usually don't even need to use bind_params() explicitly since you can supply the param arguments directly to execute().