title: php/pdo insert into database mssql with arrays
body: <p>I need some help</p>
  
  <p>Is there a way to make this in PDO? <a href="https://stackoverflow.com/a/1899508/6208408">https://stackoverflow.com/a/1899508/6208408</a>
  Yes I know I could change to mysql but I use a mssql server and can't use mysql. I tried some things but I'm not as good with PDO as mysql... It's hard to find some good examples of inserting array's into database with PDO. So quickly said I have a PDO based code connected to a mssql webserver. </p>
  
  <p>best regards joep</p>
  
  <p>I tried this before:</p>
  
  <pre><code>//id
  $com_id = $_POST['com_id'];
  //array
  
  $mon_barcode = $_POST['mon_barcode'];                   
  $mon_merk = $_POST['mon_merk'];
  $mon_type = $_POST['mon_type'];
  $mon_inch = $_POST['mon_inch'];
  $mon_a_date = $_POST['mon_a_date'];
  $mon_a_prijs = $_POST['mon_a_prijs'];
  
  $data = array_merge($mon_barcode, $mon_merk, $mon_type, $mon_inch, $mon_a_date, $mon_a_prijs);
  try{
      $sql = "INSERT INTO IA_Monitor (Com_ID, Barcode, Merk, Type, Inch, Aanschaf_dat, Aanschaf_waarde) VALUES (?,?,?,?,?,?,?)";
      $insertData = array();
  
  
      foreach($_POST['mon_barcode'] as $i =&gt; $barcode)                        
      {
          $insertData[] = $barcode;
      }
  
      if (!empty($insertData))
      {
          implode(', ', $insertData);
          $stmt = $conn-&gt;prepare($sql);
          $stmt-&gt;execute($insertData);
  
      }
  }catch(PDOException $e){
      echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
  }
  $conn = null;
  </code></pre>