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

my DBI book has both these formats:
$sth->bind->columns(\$server); while ( $sth->fetch ) { $sth->bind->columns(undef, \$server); while ( $sth->fetch ) {
Which is preferred and why, please?

Replies are listed 'Best First'.
Re: DBI bind_columns
by roboticus (Chancellor) on Sep 16, 2014 at 17:56 UTC

    fionbarr:

    You've provided no context, so I'd suggest reading the rest of the information on the page to find out why it's used in two different ways. If I had to guess, I'd suspect that you meant $sth->bind_columns and that the author wanted to either insert a null in the first column (in the event that it's an insert or similar) or ignore the results of the first column (for a select).

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      O'Reilly 'Perl DBI' page 129 has the 'undef' page 227 no 'undef'
Re: DBI bind_columns
by Tux (Canon) on Sep 17, 2014 at 06:28 UTC

    The book is a bit outdated by now. Lots of development have been done in DBI since.

    Use perldoc DBI and skip to the section about bind_columns to read:

    For compatibility with old scripts, the first parameter will be + ignored if it is "undef" or a hash reference.

    Enjoy, Have FUN! H.Merijn
      thanks