Easy Tutorial
❮ Php Csprng Func String Strtolower ❯

PHP mysqli_affected_rows() Function

PHP MySQLi Reference Manual

Example

Output the number of affected records from different queries:

<?php
// Assume database username: root, password: 123456, database: tutorialpro
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro");
if (mysqli_connect_errno($con)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Execute query and output the number of affected rows
mysqli_query($con, "SELECT * FROM websites");
echo "Number of affected rows: " . mysqli_affected_rows($con);

echo "<br>";

mysqli_query($con, "DELETE FROM websites WHERE alexa > 1000");
echo "Number of affected rows: " . mysqli_affected_rows($con);

mysqli_close($con);
?>

Definition and Usage

The mysqli_affected_rows() function returns the number of rows affected by the previous MySQL operation (SELECT, INSERT, UPDATE, REPLACE, DELETE).


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: An integer greater than 0 indicates the number of affected rows. 0 indicates no affected rows. -1 indicates that the query returned an error.
PHP Version: 5+
--- ---
❮ Php Csprng Func String Strtolower ❯