Name

do( )

Synopsis

$database_handle->do(statement[, \%attributes, @values])

This 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 an array in the third argument. Statement handle attributes may be given for the second argument.

...
my $sql_stmnt = "UPDATE books SET publisher = ?
                 WHERE publisher = ?";
$dbh->do($sql_stmnt, '', 'Oxford Univ. Press', 'OUP');
$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(). Therefore, a finish( ) isn’t required, just a disconnect() is.

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.