Name

rows( )

Synopsis

$statement_handle->rows( )

This returns the number of rows affected by the last statement handle executed. It works with UPDATE, INSERT, and DELETE dependably. It doesn’t work effectively with SELECT statements unless they select all rows in a table. If the number of rows is unknown, -1 is returned. There are no arguments to this method.

...
my $sql_stmnt = "UPDATE books SET author = 'Robert B. Parker'
                 WHERE author = 'Robert Parker'";
my $sth = $dbh->prepare($sql_stmnt);
$sth->execute( );
my $change_count = $sth->rows( );
print "$change_count rows were changed.";

This script displays the following when run:

2 rows were changed

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.