title: pdo to download database records into excel file
body: <p>So I had this working before while i used mysql functions but now how to get this to work in pdo? </p>
  
  <p>Would really appreciate if someone could help out as pdo is new to me.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>&lt;?php
  require_once('_db.php');
  $y =$_REQUEST['y'];
  $m =$_REQUEST['m'];
  $date = "$y-$m";
  $todays = date("d-m-Y");
  header('Content-Type: text/csv');
  header('Content-Disposition: attachment;filename=Reservations-'.$date.'.csv');
  $select_table=mysql_query("SELECT * FROM reservations WHERE DATE_FORMAT(date, '%Y-%m') = '$date' ORDER BY id DESC");
  $rows = mysql_fetch_assoc($select_table);
  if ($rows){
      getcsv(array_keys($rows));
  }
  while($rows){
      getcsv($rows);
      $rows = mysql_fetch_assoc($select_table);
  }
  function getcsv($no_of_field_names){
      $separate = '';
      foreach ($no_of_field_names as $field_name){
          if (preg_match('/\\r|\\n|,|"/', $field_name)){
              $field_name = '' . str_replace('', $field_name) . '';
          }
          echo $separate . $field_name;
          $separate = ',';
      }
      echo "\r\n";
  }
  ?&gt;
  </code></pre>