title: export to csv file from database using php PDO?
body: <p>i have here the code for exporting to csv file from my database using pdo.The downloading of the file works fine and it opens normally but before it opens something just always pop up every time i export it to csv file. what i want is to get rid of it.</p>
  
  <p><strong>this is the pop up message</strong></p>
  
  <p>->the file that you are trying to open is in a different format than sprecified by the file extension. verify that the file is not corrupted and is from a trusted source before opening the file.</p>
  
  <p>->excel has detected that .csv is a SYLK file, but cannot load it.Either the file has errors or is is not a SYLK file format..</p>
  
  <p><strong>user.class.php</strong></p>
  
  <pre><code>public function export($query)
  {
  $dsn = 'mysql:host=localhost;dbname=survey';
  $username = 'root';
  $password = '';
  $options = array(PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION);
  
  try {
  $db = new PDO($dsn, $username, $password, $options);
  } catch (PDOException $e) {
  $error_message = $e-&gt;getMessage();
  
  }
  
  header("Content-type: text/csv");
  header("Content-Disposition: attachment; filename=REGION V-Survey.csv");
  header("Pragma: no-cache");
  header("Expires: 0");
  
  
  try {
     $statement = $db-&gt;prepare($query);
     $statement-&gt;execute();
     $results = $statement-&gt;fetchAll();
     $statement-&gt;closeCursor();
  
     $content = '';
     $title = '';
     foreach ($results as $rs){
         $content .= stripslashes($rs["ID"]). ',';
         $content .= stripslashes($rs["Province"]). ',';
         $content .= stripslashes($rs["Date_Submitted"]). ',';
         $content .= stripslashes($rs["Survey_Number"]). ',';
         $content .= stripslashes($rs["Land_Type"]). ',';
         $content .= stripslashes($rs["C_Size"]). ',';
         $content .= stripslashes($rs["Contractor"]). ',';
         $content .= stripslashes($rs["Module_Number"]). ',';
         $content .= stripslashes($rs["LAD_Target"]). ',';
         $content .= stripslashes($rs["Fund_Year"]). ',';
         $content .= stripslashes($rs["Land_Cat"]). ',';
         $content .= stripslashes($rs["Title_Number"]). ',';
         $content .= stripslashes($rs["W_bal"]). ',';
         $content .= stripslashes($rs["Lot_Number"]). ',';
         $content .= stripslashes($rs["Proj_Number"]). ',';
         $content .= stripslashes($rs["Agency"]). ',';
         $content .= stripslashes($rs["Location"]). ',';
         $content .= stripslashes($rs["Barangay"]). ',';
         $content .= stripslashes($rs["Date_Survey"]). ',';
         $content .= stripslashes($rs["No_Lots"]). ',';
         $content .= stripslashes($rs["Area"]). ',';
         $content .= stripslashes($rs["LO_Name"]). ',';
         $content .= stripslashes($rs["Times_Returned"]). ',';
         $content .= stripslashes($rs["Times_Resubmitted"]). ',';
         $content .= stripslashes($rs["Date_Returned"]). ',';
         $content .= stripslashes($rs["Date_Resubmitted"]). ',';
         $content .= stripslashes($rs["Date_Suspended"]). ',';
         $content .= stripslashes($rs["Date_Completed"]). ',';
         $content .= stripslashes($rs["Station"]). ',';
         $content .= stripslashes($rs["Date_Approved"]). ',';
         $content .= stripslashes($rs["Date_DAR"]). ',';
         $content .= stripslashes($rs["Date_DARPO"]). ',';
         $content .= stripslashes($rs["Cert"]). ',';
         $content .= stripslashes($rs["Remarks"]). ',';
         $content .= stripslashes($rs["Date_Reported"]). ',';
         $content .= "\n";
      }
      $title .= "ID,Province,Date_Submitted,Survey_Number,Land_Type,C_Size,Contractor,Module_Number,LAD_Target,Fund_Year,Land_Cat,Title_Number,W_bal,Lot_Number,Proj_Number,Agency,Location,Barangay,Date_Survey,No_Lots,Area,LO_Name,Times_Returned,Times_Resubmitted,Date_Returned,Date_Resubmitted,Date_Suspended,Date_Completed,Station,Date_Approved,Date_DAR,Date_DARPO,Cert,Remarks,Date_Reported"."\n";
      echo $title;
      echo $content;
  
  } catch (PDOException $e) {
        echo $e-&gt;getMessage();
     exit;
  }
  }
  </code></pre>
  
  <p><strong>export.php</strong></p>
  
  <pre><code>$query = "SELECT * FROM survey_section";
  $crud-&gt;export($query);
  </code></pre>