title: PHP, MySQL - can you distinguish between rows matched and rows affected?
body: <p>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 successful or not.  I thought I could use <code>mysql_affected_rows</code>...</p>
  
  <pre><code>// Example:
  // After running query "UPDATE mytable SET name='Test' WHERE ID=1"
  $result = mysql_affected_rows();
  if ($result &gt;= 1) { /* Success */ }
  </code></pre>
  
  <p>If, for example, there was no row with <strong>ID=1</strong>, then <code>$result</code> would be <strong>0</strong>.</p>
  
  <p>However, it turns out that PHP's <code>mysql_affected_rows</code> is the actual affected rows, and may be still be <strong>0</strong> if the row exists but <code>name</code> was already "Test". (The <a href="http://php.net/manual/en/function.mysql-affected-rows.php" rel="noreferrer">PHP docs</a> even say this is the case).</p>
  
  <p>If I run this in the command line, I get the following meta information about the query:</p>
  
  <pre><code>Query OK, 0 rows affected (0.01 sec)
  Rows matched: 1  Changed: 0  Warnings: 0
  </code></pre>
  
  <p>Is there any way for me to get that "Rows matched" value in PHP instead of the affected rows?</p>
  
  <p>[<strong>Edit</strong>]: I should note that I know I can run a separate query, but I'd like to not do that, for the sake of performance.</p>