Print out affected rows from different queries in PHP

Description

The following code shows how to print out affected rows from different queries.

Example


/*w w w . j a v  a 2  s.co m*/
<?php
    $con=mysqli_connect("localhost","root","","test");
    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 employee");
    echo "Affected rows: " . mysqli_affected_rows($con);

    mysqli_query($con,"DELETE FROM employee");
    echo "Affected rows: " . mysqli_affected_rows($con);

    mysqli_close($con);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented