title: PHP PDO, Object, bindParam
body: <p>I don't manage to fill a table with a PHP Object with PDO and an object created from a JSON file. Do you see where the error comes from?
  I use PHP5 &amp; PostgreSQL</p>
  
  <p>The code I wrote sucessfully adds the lines, but only the first column (field) of each row is filled, the others remain white.</p>
  
  <p>My table structure looks like this:</p>
  
  <pre><code>CREATE TABLE ' . $infoTableName . ' (field text,type text,expefactor boolean,iduser boolean,idcontext boolean,idaction boolean,params boolean,comment text)
  </code></pre>
  
  <p>My object looks like this:</p>
  
  <pre><code>object(stdClass)[3]
    public 'timestamp' =&gt; 
      object(stdClass)[4]
        public 'idagent' =&gt; boolean false
        public 'idcontext' =&gt; boolean false
        public 'idaction' =&gt; boolean false
        public 'comment' =&gt; string 'ffff' (length=4)
    public 'order' =&gt; 
      object(stdClass)[5]
        public 'idagent' =&gt; boolean false
        public 'idcontext' =&gt; boolean false
        public 'idaction' =&gt; boolean false
        public 'comment' =&gt; string 'none' (length=4)
    public 'test' =&gt; 
      object(stdClass)[6]
        public 'idagent' =&gt; boolean false
        public 'idcontext' =&gt; boolean true
        public 'idaction' =&gt; boolean false
        public 'comment' =&gt; string 'y' (length=1)
  </code></pre>
  
  <p>And finally the PHP code:</p>
  
  <pre><code>$structure = json_decode($_POST['structure']);
  $query = "INSERT INTO " . $infoTableName . " (field, iduser, idcontext, idaction, comment) VALUES (:field, :idagent, :idcontext, :idaction, :comment)"; //Prequery
              $stmt = $db-&gt;prepare($query);
              $stmt-&gt;bindParam(':field', $key);
              $stmt-&gt;bindParam(':idagent', $value-&gt;idagent);
              $stmt-&gt;bindParam(':idcontext', $value-&gt;idcontext);
              $stmt-&gt;bindParam(':idaction', $value-&gt;idaction);
              $stmt-&gt;bindParam(':comment', $value-&gt;comment);
  
  
              foreach ($structure as $key =&gt; &amp;$value) {
                  try {
                      var_dump($stmt-&gt;execute());
                  } catch (PDOException $e) {
                      var_dump($e-&gt;getMessage());
                  }
              }
  </code></pre>
  
  <p>Do you see the error?
  Thanks a lot.</p>
  
  <p>EDIT: It looks like I am asking a too much with object in binding functions, still, here is a little workaround:</p>
  
  <pre><code>$stmt-&gt;bindParam(':field', $key);
              $stmt-&gt;bindParam(':idagent', $idagent);
              $stmt-&gt;bindParam(':idcontext', $idcontext);
              $stmt-&gt;bindParam(':idaction', $idaction);
              $stmt-&gt;bindParam(':comment', $comment);
  
  
              foreach ($structure as $key =&gt; &amp;$value) {
                  $idagent = $value-&gt;idagent;
                  $idcontext = $value-&gt;idcontext;
                  $idaction = $value-&gt;idaction;
                  $comment = $value-&gt;comment;
                  try {
                      var_dump($stmt-&gt;execute());
                  } catch (PDOException $e) {
                      var_dump($e-&gt;getMessage());
                  }
              }
  </code></pre>
  
  <p>The reason bindParam() doesn't work is when I iterate thru the $structure, $value is reinstanciated, resulting in the references being changed... I first thought &amp;$value would help, but it looks like not.</p>