title: PHP PDO MySQL Correct way to check if an update query succeeded when no rows are affected
body: <p>What is a sure way to tell if an update query succeeded when using php pdo and mysql?</p>
  
  <p>In my app, I update totals of items that are submitted but a user, and the table looks like this:</p>
  
  <p><strong>items</strong></p>
  
  <pre><code>userId | itemsAdded | itemsChecked | itemsUnChecked | itemsTotal
       1 |          5 |            2 |              3 |          5
  </code></pre>
  
  <p>So when I do <code>update items set itemTotals = itemsChecked+itemUnChecked</code> the <code>itemsTotal</code> column remains the same unless the itemsAdded changes and the itemsUnChecked increments (2 + 3 equals 5, 1 + 4 is also 5).</p>
  
  <p>I used to use rowCount() to check if a query succeeded, but in this case, since the <code>itemsTotal</code> column stays the same, there's no way of telling if the sql succeeded or not.</p>
  
  <pre><code>$query = $conn-&gt;prepare($sql);
  
  $query-&gt;execute(array(
  
      ":itemCount" =&gt; $itemCount
      ":itemId" =&gt; $itemId
  ));
  
  $queryCount = $query-&gt;rowCount();
  
  if($queryCount == 1) {
      echo 'Updated succeeded';
  } else {
      echo 'Updated failed!';
  }
  </code></pre>
  
  <p>I could also use:</p>
  
  <pre><code>$query = $conn-&gt;prepare($sql);
  
  $result = $query-&gt;execute(array(
  
      ":itemCount" =&gt; $itemCount
      ":itemId" =&gt; $itemId
  ));
  
  if($result) {
      echo 'Updated succeeded';
  } else {
      echo 'Updated failed!';
  }
  </code></pre>
  
  <p>But does that return true or false based on if the query succeed or based on the number of rows it updated?</p>
  
  <p>I only need to check if the query succeeded or not. No need to tell the number of rows that were updated.</p>