title: How can I retrieve the number of rows deleted with PDO?
body: <p>Okay, so I have been using a <a href="http://development.andrewjudd.ca/" rel="noreferrer" title="PDO Wrapper">PDO wrapper</a> for a project I'm working on, and I'm trying to find out whether a DELETE query was successful or not. Here is the code I am using:</p>
  
  <pre><code>/**
  * A pretty straight-forward query to delete a row from the verification
  * table where user_id is $user_id and code is $code
  */
  $result = $this-&gt;database-&gt;query("DELETE FROM verification " .
                                   "WHERE user_id = %u AND code = %s",
                                   $user_id,
                                   $code);
  
  /**
   * This function will grab the PDO's exec() return, which should
   * return the number of rows modified.
   */
  if($this-&gt;database-&gt;getNumAffected($result) &gt; 0)
      return true;
  else
      return false;
  </code></pre>
  
  <p>The problem is, whether the DELETE query actually deletes a row or not, $this->database->getNumAffected($result) always returns '0'.</p>
  
  <p>You can check out the wrapper, but basically $this->database->getNumAffected($result) simply returns exactly the same value PDO::exec() would return.</p>
  
  <p>I tried this code without the wrapper (directly into PDO,) and I had the same problem but reverse: it always returned '1' (whether a row was deleted or not.)</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p><strong>EDIT</strong>: Based on <a href="https://stackoverflow.com/questions/922398/what-does-a-successful-mysql-delete-return-how-to-check-if-delete-was-successful" title="Old StackOverflow Question">this</a> SO question, I'm doing everything right... I don't understand why this isn't working.</p>