mysql_affected_rows() is very useful function when we need to know how many rows affected our last MySql operation. This function returns the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query.
It will return number of rows affected by our last operation & will return -1 if the last query failed. It last query didn’t affect any row of database than it will return 0.
Example :-
<?php
$link = mysql_connect(‘localhost’, ‘milap_patel’, ‘password’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(‘milap_patel’);
/* this will return the correct numbers of deleted records */
mysql_query(‘DELETE FROM table_name WHERE field_name = “Smile”‘);
printf(“Records deleted: %d\n”, mysql_affected_rows());
?>
Output :-
Records deleted: number of records your query deleted..
Filed under: MySql, mysql_affected_rows() Tagged: mysql Image may be NSFW.
Clik here to view.

Clik here to view.
