Name
execute_array()
Synopsis
$sth->execute_array(\%attri[, @values)
Use this function to execute a prepared statement multiple
times, once for each set of values given either as the second argument
of the method or from previous uses of the
bind_param_array() method. If you use the
bind_param_array() method, you won’t provide
the array values with this execute_array()
method. For an example of this statement’s use with the
bind_param_array() method, see that
description earlier in this chapter. Here is an example without that
method:
...
my @old_names = ('Graham Green', 'Virginia Wolf');
my @new_names = ('Graham Greene', 'Virginia Woolf');
my $sql_stmnt = "UPDATE books
SET author = ?,
status = ?
WHERE author = ?";
my $sth = $dbh->prepare($sql_stmnt);
my ($tuple, $rows_chg) = $sth->execute_array(undef, \@new_names, 'active',
\@old_names);
$sth->finish();Notice that we are able to capture the number of rows changed by
the SQL statement. Since we didn’t specify any attributes, the
$tuple variable will be empty. A tuple is an
ordered list of values or objects.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access