do()
$dbh->do($sql_stmnt[, \%attri, @values])
This function executes an SQL statement without having to use
the prepare() method. It returns the number
of rows changed. The first argument contains an SQL statement. If
placeholders are used in the SQL statement, their values are provided
in a comma-separated list or in an array in the third argument.
Statement handle attributes may be given for the second argument. You
would use this method only with SQL statements that do not return data
values (e.g., use with UPDATE, not
SELECT). Here is an example:
...
my $sql_stmnt = "UPDATE books SET publisher = ?
WHERE publisher = ?";
my @values = ('Oxford Univ. Press', 'OUP');
$dbh->do($sql_stmnt, undef, @values);
$dbh->disconnect();In this example, the initials of a particular publisher are
changed to the publisher’s name. The SQL statement is executed without
a prepare() or an
execute()—that is, without a statement
handle. Therefore, a finish() isn’t required,
just a disconnect(). If you want to know the
number of rows changed, change the example like so:
... my $rows_changed = $dbh->do($sql_stmnt, undef, @values); print "Rows Changed: $rows_changed";