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);
Parameter | Description |
---|---|
Connection : | Required parameter. The MySQL connection to be used |
Return Value : | Returns integer > 0 indicates number of affected rows. 0 if no record affected |
<?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); ?>