title: fputcsv is putting duplicate values in my file
body: <p>I have read all topics about problem which was described at <code>stackoverflow</code> linked to problem of duplicated values in <code>fputcsv</code> function. Unfortunately I am using <code>PDO</code> and <code>psql</code> (presented solutions was described using simple <code>mysql</code> connectors)</p>
  
  <p>But first I will describe my problem showing some code. Here is what I put:</p>
  
  <pre><code>$db=ConnectionFactory::CreateConnection();
  
  $fileName = 'somefile.csv';
  
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header('Content-Description: File Transfer');
  header("Content-type: text/csv");
  header("Content-Disposition: attachment; filename={$fileName}");
  header("Expires: 0");
  header("Pragma: public");
  
  
      $fh = @fopen( 'php://output', 'w' );
  
  
      $query = "SELECT * FROM person";
      $results = $db-&gt;query($q)-&gt;fetchall();
  
      $headerDisplayed = false;
  
      foreach ( $results as $data ) {
          // Add a header row if it hasn't been added yet
          if ( !$headerDisplayed ) {
              // Use the keys from $data as the titles
              fputcsv($fh, array_keys($data));
              $headerDisplayed = true;
          }
  
          // Put the data into the stream
          fputcsv($fh, $data);
      }
      // Close the file
      fclose($fh);
      // Make sure nothing else is sent, our file is done
      exit;
  </code></pre>
  
  <p><code>CSV</code> file I am getting contains double values, for example:</p>
  
  <pre><code>"name","name","phone","phone","email","email"
  "John","John","501231","501231","test","test"
  "Bob","Bob","1111","1111","test2","test2"
  </code></pre>
  
  <p>When I am trying to execute function <code>pg_fetch_array</code> I am getting error:</p>
  
  <pre><code>pg_fetch_array() expect parameter 1 to be resource, array given
  </code></pre>
  
  <p>What can I do to fix my csv?</p>