title: update mysql database table fields with a single mysqli statement query
body: <p>I have a database table and i am updating the table columns this way.</p>
  
  <pre><code>    $mysqli = new mysqli('localhost', 'root', '', 'db');
  
          if (mysqli_connect_errno()) {
              echo 'failed to connect to db.. &lt;br&gt;' . mysqli_connect_errno();
              return 'error';
          }
  
     $username = $data['username'];
     $data['image'] = $this-&gt;replace_whitespace($data['image']);
  
     foreach($data as $key=&gt;$value){
  
         $this-&gt;query = "UPDATE users SET $key=? WHERE username='$username'";
         $this-&gt;statement = $mysqli-&gt;prepare($this-&gt;query);
  
         if($this-&gt;statement){
  
             $this-&gt;statement-&gt;bind_param('s', $value);
             $this-&gt;statement-&gt;execute();
             $this-&gt;statement-&gt;close();
         }
  
     }
  </code></pre>
  
  <p>Is it possible to update more than one table columns in one go. I tried this but in-vain.</p>
  
  <pre><code>   $this-&gt;query = "UPDATE users SET col1=?, col2=?, col3=? WHERE username='$username'";
     $this-&gt;statement = $mysqli-&gt;prepare($this-&gt;query);
  
     if($this-&gt;statement){
  
         $this-&gt;statement-&gt;bind_param('sss', $value1, $value2, $value3);
         $this-&gt;statement-&gt;execute();
         $this-&gt;statement-&gt;close();
     }
  </code></pre>
  
  <p>Is there a better way doing this?</p>
  
  <pre><code>        $mysqli = new mysqli('localhost', 'root', '', 'db');
  
          if (mysqli_connect_errno()) {
              echo 'failed to connect to db.. &lt;br&gt;' . mysqli_connect_errno();
              return 'error';
          }
          $username = $data['username'];
          $this-&gt;query = "UPDATE users SET fname=?, lname=?, email=?, tpin=?, image=?, address=? country=?, city=?, state=?, postal=? WHERE username='$username'";
          $this-&gt;statement = $mysqli-&gt;prepare($this-&gt;query);
  
          if ($this-&gt;statement) {
              $this-&gt;statement-&gt;bind_param('ssssssssss', $data['fname'],$data['lname'],$data['email'],$data['tpin'], $data['file'], $data['address'],$data['country'],$data['city'],$data['state'], $data['post_code']);
              $this-&gt;statement-&gt;execute();
               $this-&gt;statement-&gt;close();
         }
  </code></pre>
  
  <p>This is my real code.</p>