title: PDO PHP insert into DB from an associative array
body: <p>I have an array like this</p>
  
  <pre><code>  $a = array( 'phone' =&gt; 111111111, 'image' =&gt; "sadasdasd43eadasdad" );
  </code></pre>
  
  <p>When I do a var-dump I get this -></p>
  
  <pre><code> { ["phone"]=&gt; int(111111111) ["image"]=&gt; string(19) "sadasdasd43eadasdad" }
  </code></pre>
  
  <p>Now I am trying to add this to the DB using the IN statement -</p>
  
  <pre><code> $q = $DBH-&gt;prepare("INSERT INTO user :column_string VALUES :value_string");
   $q-&gt;bindParam(':column_string',implode(',',array_keys($a)));
   $q-&gt;bindParam(':value_string',implode(',',array_values($a)));
   $q-&gt;execute();
  </code></pre>
  
  <p>The problem I am having is that implode return a string. But the 'phone' column is an integer in the database and also the array is storing it as an integer. Hence I am getting the SQL error as my final query look like this --</p>
  
  <pre><code>INSERT INTO user 'phone,image' values '111111111,sadasdasd43eadasdad';
  </code></pre>
  
  <p>Which is a wrong query. Is there any way around it.</p>
  
  <p>My column names are dynamic based what the user wants to insert. So I cannot use the placeholders like <strong>:phone</strong> and <strong>:image</strong> as I may not always get a values for those two columns. Please let me know if there is a way around this. otherwise I will have to define multiple functions each type of update.</p>
  
  <p>Thanks.</p>