PHP mysqli_affected_rows() Function

Object oriented style

int $mysqli->affected_rows;

Procedural style

int mysqli_affected_rows ( mysqli $link )

Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.For SELECT statements mysqli_affected_rows() works like mysqli_num_rows().

The mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.

Examples -

Object oriented style

Procedural style

ParameterDescription
linkProcedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

Return Values

An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error.