MySQLi - Affected Rows



Syntax

mysqli_affected_rows(connection);

Definition and Usage

It used to get the information about number of affected rows in a previous MySQL operation.

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   } 
   echo"Database connected \n";
   
   $sql = "SELECT * FROM Tutorials_auto";
   mysqli_query($conn,$sql); 
   echo "Affected rows: " . mysqli_affected_rows($conn);
   
   $conn->close();
?>

The sample output of the above code should be like this −

Database connected Affected rows: 2
mysqli_useful_functions.htm
Advertisements