|
mysql_affected_rowsGet number of affected rows in previous MySQL operation Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:
Description
int mysql_affected_rows(resource
$link_identifier = NULL)
Get the number of affected rows by the last INSERT, UPDATE, REPLACE
or DELETE query associated with Parameters
Return ValuesReturns the number of affected rows on success, and -1 if the last query failed. If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2. When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows may not actually equal the number of rows matched, only the number of rows that were literally affected by the query. The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.
In the case of "INSERT ... ON DUPLICATE KEY UPDATE" queries, the
return value will be Examples
Example #1 mysql_affected_rows example
The above example will output something similar to: Records deleted: 10 Records deleted: 0
Example #2 mysql_affected_rows example using transactions
The above example will output something similar to: Updated Records: 10 Notes
See Also
|