Name
bind_columns
Synopsis
$rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
Calls
bind_col
for each column of the SELECT
statement. The
bind_columns
method will die if the number of
references does not match the number of fields.
For maximum portability between drivers,
bind_columns
should be called after
execute
.
For example:
$dbh->{RaiseError} = 1; # Do this, or check every call for errors $sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region }); $sth->execute; my ($region, $sales); # Bind Perl variables to columns: $rv = $sth->bind_columns(\$region, \$sales); # You can also use Perl's \(...) syntax (see perlref docs): # $sth->bind_columns(\($region, $sales)); # Column binding is the most efficient way to fetch data while ($sth->fetch) { print "$region: $sales\n"; }
For compatibility with old scripts, the first parameter will be
ignored if it is undef
or a hash reference.
Get Programming the Perl DBI now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.