title: PHP generate dynamic PDO insert
body: <p>The following code should insert each key-value pair in an array into a mathing column-value in a table. The script returns no errors but the the inserted row contains only the last value in the array</p>
  
  <p>E.g.</p>
  
  <pre><code>array('one'=&gt;1,'two'=&gt;2,'three'=&gt;3);
  </code></pre>
  
  <p>insert the row successfully in a table with columns one, two and three but insert the value 3 in all.</p>
  
  <pre><code>    $columns = array();
      $bind = '';
      foreach($array as $key =&gt; $value){
  
          $columns[] = $key;
  
      }
  
      $columnString = implode($columns,',');
      $valueString = implode($columns,',:');
      $valueString = ':' . $valueString;
  
      $core = core::getInstance();
      $STH = $core-&gt;dbh-&gt;prepare("INSERT INTO table (" . $columnString . ") VALUES 
      (" . $valueString . ")");
  
      foreach($array as $key =&gt; $value){
  
          $STH-&gt;bindParam(':' . $key,$value);
      }
  </code></pre>