Name

bind_col( )

Synopsis

$statement_handle->bind_col(index, \$variable[, \%attributes])

This associates or binds a column from a statement handle to a given variable. The values are updated when the related row is retrieved using a fetch method, without extra copying of data.

...
my $sql_stmnt = "SELECT title, author FROM books";
my $sth = $dbh->prepare($sql_stmnt);
$sth->execute( );
$sth->bind_col(1, \$title);
$sth->bind_col(2, \$author);
while($sth->fetch( )) {
   print "$title by $author \n";
}

A separate statement has to be issued for each bind. To bind multiple columns in one statement, use bind_columns( ).

Get MySQL in a Nutshell 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.