What are mysql_affected_rows in PHP

mysql_affected_rows

description

int mysql_affected_rows ([resource connection identifier])

mysql_affected_rows () returns the number of data records affected by the last INSERT, UPDATE or DELETE request to the server that is associated with the specified. If the connection identifier is not specified, the last one is followed by mysql_connect () open connection accepted.

Annotation: If you are using Transactions, you must mysql_affected_rows () Call immediately after your INSERT, UPDATE, or DELETE request, not after the commit.

If the last request was a DELETE statement without a WHERE condition, all data records were deleted from the table. However, this function will still return zero (0).

Annotation: If you use UPDATE, MySQL will not update any columns where the new value corresponds to the old value. That can lead to mysql_affected_rows () does not return the actual number of rows affected, but only those that are literally affected by the query.

This function does not work in connection with SELECT queries, but only with statements that change data records. Use the function to get the number of delivered data records of a SELECT query mysql_num_rows ().

If the last request fails, this function returns -1.

Example 1. Delete query

The above example outputs the following:

Data records deleted: 10 data records deleted: 0

Example 2. Update query

The above example outputs the following:

Changed data sets: 10

See also: mysql_num_rows (), mysql_info ().