title: Inserting array data using PDO prepared statements
body: <p>Im slowly getting the hang of PDO and prepared statements, but could someone please clarify the following:</p>
  
  <p>I understand you can insert data from an array using the following code:</p>
  
  <pre><code>$values = array('bill', 'ben', 'bob');
  
  $stmt = $db-&gt;prepare("INSERT INTO first_page_data(first_name) VALUES(:fname)");
  $stmt-&gt;bindParam(':fname', $first_name, PDO::PARAM_STR);
  foreach ($values as $first_name) {
      $stmt-&gt;execute();
  }
  </code></pre>
  
  <p>This will insert the three names into 3 new rows in the database, no problems here!</p>
  
  <p>However if I have an array containing the database column names and a corresponding array containing the values, is there a way of inserting multiple <strong>columns</strong> for the same user in one prepared statement rather than typing out the (rather monotonous) line of code:</p>
  
  <pre><code>$stmt = $db-&gt;prepare("INSERT INTO first_page_data(first_name,surname,phone_no,email,postcode) VALUES(:fname,:sname,:phone,:email,:postcode)");
  </code></pre>
  
  <p>IE in the brackets after the table name, just have an array variable rather than listing out the column names.</p>
  
  <p>Also if I use unnamed placeholders in my prepared statement, can I iterate through the POST array from a form to bind the values to the <code>?</code> placeholders? (instead of typing multiple <code>$stmt-&gt;bindValue(.......)</code> lines?</p>