title: PHP Prepared Statements fails to assign correct values
body: <p>What i'm trying to do is to insert multiple rows of key/value pairs. The Entries need to be Unique (PrimaryKeys to be specific).</p>
  
  <p>The statement is prepared with the count of values to insert:</p>
  
  <pre><code>$sql = "INSERT INTO `test_values` (`foreignID1`,`value`) VALUES";
  
  for($ix=0;$ix&lt;count($values);$ix++){
      if($ix&gt;0){ $sql.= ", ";}
      $sql .= "(:parentID,:value$ix)";
  }
  
  echo $sql; //INSERT INTO `test_values` (`parentID`,`value`) VALUES (:parentID,:value0), (:parentID,:value1)
  </code></pre>
  
  <p>then, when preparing the statement i loop the values:</p>
  
  <pre><code>$stmt = $dbh-&gt;prepare($sql);
  $stmt-&gt;bindParam(':parentID',$parentID);
  
  foreach($values as $key =&gt; $value){
      $valName = ":value$key";
  
      var_dump($valName);
      var_dump($value);
  
      $stmt-&gt;bindParam($valName,$value);
  }
  </code></pre>
  
  <p>the dumps tell me that every time other values are (correctly) assigned:</p>
  
  <pre><code>string(7) ":value0"
  string(14) "one.domain.com"
  string(7) ":value1"
  string(18) "another.domain.com"
  </code></pre>
  
  <p>still, i get the SQL error:</p>
  
  <pre><code>Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '18-another.domain.com' for key 'PRIMARY'
  </code></pre>
  
  <p>i definitely know that these entries do not exist. I highly suspect the PDOStatement to bind the same value twice, but i have no idea why it should do so.</p>
  
  <hr>
  
  <p><strong>[EDIT]:</strong> suggested answer implemented, new output:</p>
  
  <pre><code>string(7) ":parent0"
  string(14) "18"
  string(7) ":value0"
  string(14) "one.domain.com"
  string(7) ":parent1"
  string(14) "18"
  string(7) ":value1"
  string(18) "another.domain.com"
  </code></pre>
  
  <p>still the same error.</p>
  
  <hr>
  
  <p><strong>[EDIT2]:</strong> to avoid discussions:</p>
  
  <pre><code>INSERT INTO `test_values` (`parentID`,`value`) VALUES ('18','one.domain.com'),('18','another.domain.com')
  </code></pre>
  
  <p>applied directly to the database, using phpMyAdmin, works like a charm...what i fear happens to my statement is that the values somehow aren't correctly set, and something like this results:</p>
  
  <pre><code>INSERT INTO `test_values` (`parentID`,`value`) VALUES ('18','another.domain.com'),('18','another.domain.com')
  </code></pre>
  
  <p>because the constraint always fails on the <strong>LAST</strong> entry, no matter how many i try to insert.</p>
  
  <hr>
  
  <p><strong>[EDIT3]:</strong></p>
  
  <p>table structure, as asked:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `test_values` (
    `foreignID1` int(11) NOT NULL,
    `value` varchar(256) NOT NULL,
    PRIMARY KEY (`foreignID1`,`value`)
  )
  </code></pre>
  
  <hr>
  
  <p><strong>[EDIT4]:</strong></p>
  
  <p>what DOES work is not to use the chained insert, but single ones for each value:</p>
  
  <pre><code>$sql = "INSERT INTO `test_values` (`foreignID1`,`value`) VALUES (:parendID,:value)";
  foreach($values as $key =&gt; $value){
      $stmt = $dbh-&gt;prepare($sql);
  
      $stmt-&gt;bindParam(":parendID",$parentID);
      $stmt-&gt;bindParam(":value",$value);
  
      $stmt-&gt;execute();  
  }
  </code></pre>
  
  <p>....but that's not the actual point of the question.</p>