title: PDO MYSQL Update Only If Different
body: <p>I have a web program which allows the administrator to update a user's information...  With that being said, I only want columns updated which have indeed been 'updated'...</p>
  
  <p>I have done quite a bit of researching on this and it seems that all methods use outdated querys, which do not make use of the <code>prepare</code> statement to escape input...</p>
  
  <p>Can someone please help me with the statement?</p>
  
  <p>Essentially in psuedocode:
  <code>Update FIRSTNAME if $editedUserdata['firstname'] != FIRSTNAME,  LASTNAME if $editedUserData['lastname']</code> != LASTNAME  ...etc...</p>
  
  <p>Here is what I have for the post code...</p>
  
  <pre><code>        $password = sha1($password);
          $editedUserData = array(
                'firstname' =&gt; $firstname,
                'lastname' =&gt; $lastname,
                'username' =&gt; $username,
                'password' =&gt; $password,
                'cellphone' =&gt; $cellphone,
                'security_level' =&gt; $seclvl,
                'email' =&gt; $email,
                'direct_phone' =&gt; $direct,
                'ext_num' =&gt; $extension,
                'is_active' =&gt; $userflag
              );
  </code></pre>
  
  <p>Then it should be something like</p>
  
  <pre><code>$query = $this-&gt;db-&gt;prepare('UPDATE FIRSTNAME if(?) IS NOT FIRSTNAME, LASTNAME if(?) IS NOT LASTNAME, USERNAME if (?) IS NOT USERNAME.... VALUES (:firstname, :lastname, :username).....'
  
  if ($query -&gt; execute($editedUserData)) {
      more code....
  </code></pre>