title: PHP - MySQL prepared statement to INSERT an array
body: <p>I'm editing a script that is using MySQLi. I need to use prepared statement to insert some values into the db.</p>
  
  <p>My array is in the form of:</p>
  
  <pre><code>$insert = array('column1' =&gt; 'value1', 'column2' =&gt; 'value2', 'column3' =&gt; 'value3')
  </code></pre>
  
  <p>I have this so far but I need help with the <code>bind_param</code> portion. I've seen documentation on here where <code>call_user_func_array</code> is used but I'm not sure how to implement this.</p>
  
  <pre><code>$cols = array_keys($insert);
  $query = "INSERT IGNORE INTO results (". implode(", ", $cols) .") VALUES (". implode(', ', array_fill(0, count($insert), '?')) .")";
  $stmt = $mysqli-&gt;prepare($query);
  $param = array_merge(array(str_repeat('s', count($insert))), array_values($insert)); 
  call_user_func_array(array($stmt, 'bind_param'), $param); 
  $stmt-&gt;execute();
  </code></pre>
  
  <p>PHP 5.4.17</p>