Export DB table in csv format with columns separated by semicolons

Asked

Viewed 265 times

0

I can already export in CSV, but the columns are coming apart by vírgula, how to make them come apart by ponto e vírgula?

My code:

<?php  
      //export.php  
 if(isset($_POST["export"]))  
 {  
      $connect = mysqli_connect("localhost", "root", "", "simrede");  
      header('Content-Type: text/csv; charset=utf-8');  
      header('Content-Disposition: attachment; filename=Cadastro_Alunos-Simrede.csv');  
      $output = fopen("php://output", "w");  
      fputcsv($output, array('lastname', 'firstname', 'department', 'institution', 'username',  'email', 'city', 'course1', 'password'),';');  
      $query = "SELECT * from cs_alunos ORDER BY institution";  
      $result = mysqli_query($connect, $query);  
      while($row = mysqli_fetch_assoc($result))  
      {
           fputcsv($output, $row);  
      }  
      fclose($output);  
 }  
 ?>  

1 answer

3


Following his own documentation, just guess the flag string $delimiter = "," changing to ";"

$out = fopen('php://output', 'w');
fputcsv($out, array('this','is some', 'csv "stuff", you know.'),';');
fclose($out);
  • Thanks @Israelzebulon ! Very simple, I’ll read the documentation.

  • did not work properly, only the header comes with semicolon

  • have to add in while also to fucionar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.