Perl DBI 常用方法详解
在 Perl 编程中,DBI(Database Independent Interface)提供了一系列强大的方法来与数据库进行交互。下面将详细介绍一些常用的 DBI 方法及其使用示例。
1. execute_array( )
此方法用于多次执行预准备语句,每次使用一组给定的值。这些值可以作为方法的第二个参数提供,也可以通过之前使用的 bind_param_array( )
方法提供。如果使用了 bind_param_array( )
方法,则不需要在 execute_array( )
中提供数组值。
示例代码 :
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-&g