THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP mysqli_affected_rows() Function

PHP MySQLi Reference PHP MySQLi Reference

Example

Print out affected rows from different queries:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Perform queries and print out affected rows
mysqli_query($con,"SELECT * FROM Persons");
echo "Affected rows: " . mysqli_affected_rows($con);

mysqli_query($con,"DELETE FROM Persons WHERE Age>32");
echo "Affected rows: " . mysqli_affected_rows($con);

mysqli_close($con);
?>

Definition and Usage

The mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.


Syntax

mysqli_affected_rows(connection);

Parameter Description
connection Required. Specifies the MySQL connection to use

Technical Details

Return Value: An integer > 0 indicates the number of rows affected. 0 indicates that no records were affected. -1 indicates that the query returned an error
PHP Version: 5+

PHP MySQLi Reference PHP MySQLi Reference