title: PHP PDO Insert Method
body: <p>I'm working on a PHP class method to insert form values into mysql database with PDO. The idea is outlined below but I cannot figure out how to pass in the fourth parameter of the method. Could someone explain how to do this?</p>
  
  <p>Thank you!</p>
  
  <pre><code>&lt;?php
  class Contact {
     private $DbHost = DB_HOST;
     private $DbName = DB_NAME;
     private $DbUser = DB_USER;
     private $DbPass = DB_PASS;
  
     public function MySqlDbInsert($DbTableName, $DbColNames, $DbValues, $DbBindParams){
      try{
          $dbh = new PDO("mysql:host=$this-&gt;DbHost;dbname=$this-&gt;DbName",$this-&gt;DbUser,$this-&gt;DbPass, array(PDO::ATTR_PERSISTENT =&gt; true));
          $dbh-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
          $dbh-&gt;exec("SET CHARACTER SET utf8");
  
          $sth = $dbh-&gt;prepare("INSERT INTO $DbTableName($DbColNames) VALUES ($DbValues)");
          // i know this is all wrong ----------------
          foreach($DbBindParams as $paramValue){
              $sth-&gt;bindParam($paramValue);
          }
          // ----------------------------------------
          $sth-&gt;execute();
      }
      catch(PDOException $e){
          $this-&gt;ResponseMessage(true, 'Database access FAILED!');
      }
  }
  
  $object = new Contact();
  $object-&gt;MySqlDbInsert(
      'DbTableName',
      'DbColName1, DbColName3, DbColName3',
      ':DbColValue1, :DbColValue2, :DbColValue3',
      // this part is all wrong -------------------
      array(
      ':DbColValue1', $col1, PDO::PARAM_STR,
      ':DbColValue2', $col2, PDO::PARAM_STR,
      ':DbColValue2', $col3, PDO::PARAM_STR
      )
      // ------------------------------------------
  );
  </code></pre>