bind_columns

bind_columns is very similar to the bind_col method. With bind_columns however, all of the columns returned by the query are bound in one statement. This allows you to bind several columns with a single statement.

Example:

my ($title, $price, $author); my $sql = "SELECT title, price, author FROM library"; my $query_handle = $conn->prepare($sql); $query_handle->execute(); $query_handle->bind_columns(undef, \($title, $price, $author)); while($query_handle->fetch) {     print "Author: $author, Title: $title, Price: $price\n"; } 

In this example, we don’t have to worry about binding each column, one at a time. Instead, we accomplish binding all the variables with one statement. One note about using this function is that you must have exactly the same number of variables to bind to as the SQL statement returns. If you are doing a SELECT * and there are eight fields, you must have eight variables in the bind_columns function call, even if you don’t intend on using all of them.

The arguments to bind_columns are similar to the bind_col function. The first argument is not used by MySQL, but some DBDs may use it. If it is used, a hash of attributes is expected. The second argument is a reference to a list of scalar variables.



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net