I am trying to write a PHP-MySQL database processor that is somewhat intelligent. When this processor decides it needs to make an update, I want to report if it was really
From the MySQL documentation for mysql_affected_rows
:
For UPDATE statements, if you specify the CLIENT_FOUND_ROWS flag when connecting to mysqld, mysql_affected_rows() returns the number of rows matched by the WHERE clause. Otherwise, the default behavior is to return the number of rows actually changed.
With mysqli, you can specify the CLIENT_FOUND_ROWS using mysqli::real_connect.
$db = mysqli_init();
$db->real_connect('host', 'username', 'password', 'dbname', '3306', null, MYSQLI_CLIENT_FOUND_ROWS);
In PDO, the constant is named PDO::MYSQL_ATTR_FOUND_ROWS
$db = new PDO('mysql:dbname=mydatabase;host=myhost', 'username', 'password', array(
PDO::MYSQL_ATTR_FOUND_ROWS => true
));
With the old and deprecated MySQL extension, you can specify the CLIENT_FOUND_ROWS passing the value 2 as the 5th parameter for mysql_connect (source).
You can also use the function
$variable = mysql_info();
That function retrieves a string like this:
Rows matched: 1 Changed: 0 Warnings: 0
You can work with strings functions on your variable to extract the substring with the number of rows that matched and you should have it!