These operations are treated somewhat differently than querying, as
they do not use the notion of a cursor to iterate through a result
set. They simply affect rows of data stored within tables without
returning any rows to your programs. As such, the full
prepare-execute-fetch-deallocate cycle is not as appropriate for
these operations. The fetch stage simply doesn't apply.
Since you're usually going to invoke these statements only
once, it would be very tiresome to have to call prepare(
) to get a statement handle and then call execute(
) on that statement handle to actually invoke it, only to
immediately discard that statement handle.
### Assuming a valid database handle exists....
### Delete the rows for Stonehenge!
$rows = $dbh->do( "
DELETE FROM megaliths
WHERE name = 'Stonehenge'
" );
To signify whether or not the SQL statement has been successful, a
value is returned from the call signifying either the number of rows
affected by the SQL statement, or undef if an
error occurred.
Some databases and some statements will not be able to return the
number of rows affected by some statements; -1
will be returned in these cases.