title: PDO execute returns 1 but no row affected?
body: <p>I am getting some weird behavior when using my PDO delete method and I'm hoping to get some answers why. For some reason, when I perform a delete (in this case the table is empty) the query returns 1. According to the documentation, it should be returning 0 if no rows are modified. Here is the code.</p>
  
  <pre><code>protected function dsn() {
      return 'mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;db . ';charset=' . $this-&gt;charset;
  }
  
  //my PDO attribute options//
  protected $options = [
          PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
          PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC
          ];
  //I have separate connections for different queries with different permissions
  depending on what I need to do//
  protected function connectDelete() {
      $dsn = $this-&gt;dsn();
      $this-&gt;pdo = new PDO($dsn, $this-&gt;userDelete, $this-&gt;passDelete, $options);
  
      return $this-&gt;pdo;
  }
  
  function deleteQuery($query, $values = []) {
  
      $prepare = $this-&gt;connectDelete()-&gt;prepare($query);
      $result = $prepare-&gt;execute($values);
  
      return $result;
  }
  </code></pre>
  
  <p>With all of the relevant code out of the way, here is the query.</p>
  
  <pre><code>require_once $root.'/classes/userDB.php';
  $db = new userDB();
  
  $query = "DELETE FROM table WHERE primaryKey = ? AND user_id = ?";
  $values = [$pk_id,$user_id];
  $result = $db-&gt;deleteQuery($query, $values);
  
  echo $result;
  returns 1
  </code></pre>
  
  <p>Am I doing something wrong?</p>
  
  <p><strong>EDIT #1 :</strong><br>
  So I tried <code>rowCount()</code> to see what the outcome would be, and I got the following error.</p>
  
  <blockquote>
    <p>Fatal error: Call to a member function rowCount() on a non-object...</p>
  </blockquote>
  
  <p>So seems that the query is failing?</p>
  
  <p><strong>EDIT #2 :</strong><br>
  Here is the new function that will return the affected rows.</p>
  
  <pre><code>function deleteQuery($query, $values = []) {
  
      $prepare = $this-&gt;connectDelete()-&gt;prepare($query);
      $prepare-&gt;execute($values);
      $result = $prepare-&gt;rowCount();
  
      return $result;
  }
  </code></pre>