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

Hi all, I can get the only one item by using DBI bind_columns, and if the select statement will return multiple results, how can i get all of them? thanks, Phillip
  • Comment on how to deal with multiple results returned by select statement

Replies are listed 'Best First'.
Re: how to deal with multiple results returned by select statement
by mje (Curate) on Jun 28, 2011 at 09:38 UTC

    Do you mean the result-set has more than one row? If so, call fetch again. If you mean there can be more than one different result-set you'll need to tell us at least the driver you are using and perhaps an example.

      thanks,as following your suggestion, i have fixed it by using rows and fetch() to get all return items.
Re: how to deal with multiple results returned by select statement
by moritz (Cardinal) on Jun 28, 2011 at 10:06 UTC
    The typical workflow is
    my $sth = $dbh->prepare_cached($sql); # or simply ->prepare $sth->execute(@arguments) $sth->bind_columns(\my ($id, $name, other columns ...)); while ($sth->fetch) { print "$id: $name\n"; }
Re: how to deal with multiple results returned by select statement
by locked_user sundialsvc4 (Abbot) on Jun 28, 2011 at 13:27 UTC

    I routinely use fetchrow_hashref.