PHP mysqli: affected_rows() function
mysqli_affected_rows() function / mysqli::$affected_rows
The mysqli_affected_rows() function / mysqli::$affected_rows returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.
Syntax:
Object oriented style
int $mysqli->affected_rows;
Procedural style
int mysqli_affected_rows ( mysqli $link )
Usage:
mysqli_affected_rows(connection);
Parameter:
Name | Required/Optional | Description |
---|---|---|
connection | Required | Specifies the MySQL connection to use |
Return value:
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.
Version: PHP 5, PHP 7
Example of object oriented style:
Output:
Affected rows (INSERT): -1 Affected rows (UPDATE): -1 Affected rows (DELETE): -1 Affected rows (SELECT): -1
Example of procedural style:
Output:
Affected rows (INSERT): -1 Affected rows (UPDATE): -1 Affected rows (DELETE): -1 Affected rows (SELECT): -1
See also
Previous: ftp_exec
Next: autocommit