Knowledgebase:MySQLi
Fungsi mysqli_affected_rows()
Posted by Ari Sigit on 10 June 2019 11:20 am
Definisi dan Penggunaan
Fungsi mysqli_affected_rows () mengembalikan jumlah baris yang terpengaruh di SELECT, INSERT, UPDATE, REPLACE, atau DELETE query sebelumnya.
Contoh Script:
<?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);
?>