title: PHP PDO bindParam not working with array content
body: <p>I have a mechanism that's designed to allow a user to control the <em>order</em> in which <em>products</em> appear in a <em>product group</em>. There's a "<code>grouplines</code>" table (<strong>MySQL</strong>) with columns for <code>group_id</code>, <code>product_id</code>, and <code>manual_order</code>.  The first two assign <em>products</em> to <em>groups</em>, the third determines the <em>order</em>.</p>
  
  <p>The <code>manual_order</code> values start with <strong>10</strong> and go up in increments of <strong>10</strong>.  So, for example, moving a <em>product</em> to be 3rd in the list, is simply a case of changing it's <code>manual_order</code> value to 25, and then re-calculating the <code>manual_order</code> values.  This is done by obtaining a list of <em>product ids</em>, ordered by <code>manual_order</code>, and renumbering them in increment.</p>
  
  <p>This piece of code works:</p>
  
  <pre><code>$products = array();
  $dbh = s3_pdo::get_connection();
  $query = $dbh-&gt;prepare('SELECT product_id FROM grouplines WHERE group_id=:group_id ORDER BY manual_order');
  $query-&gt;bindValue(':group_id', $group_id);
  $query-&gt;execute();
  $rows = $query-&gt;fetchAll();
  $query-&gt;closeCursor();
  if ($rows) {
      $query = $dbh-&gt;prepare('UPDATE grouplines SET manual_order=:manual_order WHERE group_id=:group_id AND product_id=:product_id');
      $query-&gt;bindValue(':group_id', $group_id);
      //$query-&gt;bindParam(':product_id', $row['product_id']);
      $query-&gt;bindParam(':product_id', $product_id);
      $query-&gt;bindParam(':manual_order', $i);
      $i = 10;
      foreach ($rows as $row) {
          $product_id = $row['product_id'];
          $query-&gt;execute();
          $i += 10;
      }
  }
  </code></pre>
  
  <p>This does not:</p>
  
  <pre><code>$products = array();
  $dbh = s3_pdo::get_connection();
  $query = $dbh-&gt;prepare('SELECT product_id FROM grouplines WHERE group_id=:group_id ORDER BY manual_order');
  $query-&gt;bindValue(':group_id', $group_id);
  $query-&gt;execute();
  $rows = $query-&gt;fetchAll();
  $query-&gt;closeCursor();
  if ($rows) {
      $query = $dbh-&gt;prepare('UPDATE grouplines SET manual_order=:manual_order WHERE group_id=:group_id AND product_id=:product_id');
      $query-&gt;bindValue(':group_id', $group_id);
      $query-&gt;bindParam(':product_id', $row['product_id']);
      //$query-&gt;bindParam(':product_id', $product_id);
      $query-&gt;bindParam(':manual_order', $i);
      $i = 10;
      foreach ($rows as $row) {
          //$product_id = $row['product_id'];
          $query-&gt;execute();
          $i += 10;
      }
  }
  </code></pre>
  
  <p>As you can see, the difference is that the second piece of code binds <code>$product_id</code> which is given a value <code>(from $row['product_id'])</code> with the <em>foreach loop</em>, whereas the first piece of code tries to bind <code>$row['product_id']</code> outside of the <em>loop</em>... which as far as I'm aware ought to work, but doesn't.</p>
  
  <p>I can only guess at why the second piece of code doesn't work, because I can't find a definite answer. I'd like a definite answer because I'm new to using the <code>PDO</code> and don't want to fall foul of this kind of thing as I convert the rest of my system to using the <code>PDO</code> instead of the old <em>mysql_</em> functions.</p>