PHP mysqli_affected_rows() Function

PHP mysqli_affected_rows() function is called on a database connection and returns the number of affected rows in the previous MySQL operation.

Syntax

mysqli_affected_rows(connection);

mysqli_affected_rows() Function Parameter

ParameterDescription
Connection :Required parameter. The MySQL connection to be used

mysqli_affected_rows() Function Return Value

Return Value :Returns integer > 0 indicates number of affected rows. 0 if no record affected

mysqli_affected_rows() Function Example

<?php
$con = mysqli_connect("localhost","user","password","db");
if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$insert_member_sql = "INSERT INTO members (id, username) VALUES('$id', '$username')";
mysqli_query($con, $insert_member_sql);

if(mysqli_affected_rows($con) > 0)
	echo "Rows Affected " . mysqli_affected_rows($con);
else
echo "0 Rows Affected ";
mysqli_close($con);
?>