Why does PDO rowCount() return 0 after UPDATE a table without modifying the existing data?
<p>I am reading a tutorial on how to insert and update data into a MySQL table using PHP, the code is listed below. My problem is when i click update but I have not modified any data, rowCount() returns 0 and breaks the code.</p>

<p>My question is, If I am simply updating the database with the same values that are in the database, why does rowCount() return zero? My thoughts were that even though it was the same data it would be inserted anyway and return a count of the updated rows? I am guessing that it check the data before it try's the update? Can anyone shed some light on this for me and suggest a workaround? I have been starring at the code for hours and have been unable to come up with anything, thanks.</p>

<pre><code>&lt;?php
require_once('../includes/connection.inc.php');
// initialize flags
$OK = false;
$done = false;
// create database connection
$conn = dbConnect('write', 'pdo');
if (isset($_GET['article_id']) &amp;&amp; !$_POST) {
    // prepare sql query
    $sql = 'SELECT article_id, title, article FROM blog WHERE article_id = ?';
    $stmt = $conn-&gt;prepare($sql);
    // bind the results
    $stmt-&gt;bindColumn(1, $article_id);
    $stmt-&gt;bindColumn(2, $title);
    $stmt-&gt;bindColumn(3, $article);
    // execute query by passing array of variables
    $OK = $stmt-&gt;execute(array($_GET['article_id']));
    $stmt-&gt;fetch();
}
// if form has been submitted, update record
if (isset($_POST['update'])) {
    //prepare update query
    $sql = 'UPDATE blog SET title = ?, article = ? WHERE article_id = ?';
    $stmt = $conn-&gt;prepare($sql);
    // execute query by passing array of variables
    $stmt-&gt;execute(array($_POST['title'], $_POST['article'], $_POST['article_id']));
    $done = $stmt-&gt;rowCount();
}
// redirect page on sucess or if $_GET['article_id'] not defined
if ($done || !isset($_GET['article_id'])) {
    header('Location: http://localhost/PHP_Solutions/admin/blog_list_pdo.php');
    exit();
}
// store error message if query fails
if (isset($stmt) &amp;&amp; !$OK &amp;&amp; !$done) {
    $error = $stmt-&gt;errorInfo();
    if (isset($error[2])) {
        $error = $error[2];
    }
}
?&gt;
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Update Blog Entry&lt;/title&gt;
&lt;link href="../styles/admin.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;h1&gt;Update Blog Entry&lt;/h1&gt;
&lt;p&gt;&lt;a href="blog_list_pdo.php"&gt;List all entries &lt;/a&gt;&lt;/p&gt;
&lt;?php if (isset($error[2])) {
    echo "&lt;p class='warning'&gt;Error: $error[2]&lt;/p&gt;";
    echo '&lt;pre&gt;';
    print_r($_POST);
    print_r($error);
    echo '&lt;/pre&gt;';
}
if ($article_id == 0) { ?&gt;
    &lt;p class="warning"&gt;Invalid request: record does not exist.&lt;/p&gt;
&lt;?php } else { ?&gt;
&lt;form id="form1" method="post" action=""&gt;
    &lt;input name="article_id" type="hidden" value="&lt;?php echo $article_id; ?&gt;"&gt;
  &lt;p&gt;
    &lt;label for="title"&gt;Title:&lt;/label&gt;
    &lt;input name="title" type="text" class="widebox" id="title" value="&lt;?php echo htmlentities($title, ENT_COMPAT, 'utf-8'); ?&gt;"&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="article"&gt;Article:&lt;/label&gt;
    &lt;textarea name="article" cols="60" rows="8" class="widebox" id="article"&gt;&lt;?php echo htmlentities($article, ENT_COMPAT, 'utf-8'); ?&gt;&lt;/textarea&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;input type="submit" name="update" value="Update Entry" id="update"&gt;
  &lt;/p&gt;
&lt;/form&gt;
&lt;?php } ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
