Data Export (CSV)

How to export data from a table into a CSV file ?

Each collector can call the method downloadCSVBySQL which allows you to export all or part of the data from a table to a CSV file.

 function downloadCSVBySQL($sql, $forExcel = false, $firstLine = array(), $addActionColumn = false) { }


  1. $sql : an SQL query.
  2. $forExcel : passed as true, this is sort of manage a good display if one wants to open the CSV file in Excel.
  3. $firstLine : a table with values that correspond to the labels that appear in column header in Excel.
  4. $addActionColumn : past to true, this parameter has the effect of adding an empty column "Action" which will be a role for data import.


The following example allows you to retrieve a file .csv is thus presented in Excel.

$this->collector['example']->downloadCSVBySQL('SELECT id_example, lib, n_order FROM gen_example', $forExcel = true, array('ID', 'Title', 'Order'), $addActionColumn = false);