PHP – Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query.

The given PHP example helps you to get the number of affected rows by the last INSERT, UPDATE,
REPLACE or DELETE query associated with link_identifier.

Code Example:
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "";

$conn =  mysql_connect($server, $username, $password) or die("Couldn't connect to MySQL" . mysql_error());
mysql_select_db($database);

$query = "UPDATE mytable SET title = 'test' WHERE status = 'Y'";
$result = mysql_query($query);
print "Total row updated: ".mysql_affected_rows(); // return -1 if last query is failed.
mysql_close($conn);
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *