The mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.
PHP mysqli_affected_rows() Function has the following syntax.
mysqli_affected_rows(connection);
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
It returns
The following code prints out affected rows from different queries.
<?php/*from w ww . j a v a2 s . c om*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"SELECT * FROM emp");
echo "Affected rows: " . mysqli_affected_rows($con);
mysqli_close($con);
?>