You are here : phpmysqlmysql_affected_rows

mysql_affected_rows() - mysql

Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier.


Syntax

int mysql_affected_rows ([ resource $link_identifier = NULL ] )


Example

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

/* this should return the correct numbers of deleted records */
mysql_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d
", mysql_affected_rows());

/* with a where clause that is never true, it should return 0 */
mysql_query('DELETE FROM mytable WHERE 0');
printf("Records deleted: %d
", mysql_affected_rows());
?>


Output / Return Value

Records deleted: 10
Records deleted: 0


Limitations

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.


Alternatives / See Also

The MySQLi or PDO_MySQL Should be used.

MySQLi - mysqli_affected_rows()


Reference

http://in.php.net/manual/en/function.mysql-affected-rows.php