wim niemans - 2021-01-07 16:06:09
We'll use the Absinter class for this example.
Assume your sql looks like 'SELECT {properties} from {table}'.
A minimal config is needed telling what properties you need, like:
$properties = ['firstName', 'lastName', 'email' ];
$table = 'my_relational_table';
$sql = 'SELECT ' . join(', ', $properties) . ' FROM ' . $table . ';';
$csv_header = "'" . join("','", $properties) . "'"; // 'firstName', 'lastName', 'email'
$csv_detail = "{" . join("},{", $properties) . "}"; // '{firstName}', '{lastName}', '{email}'
$absinter = new Absinter();
$recordset = dbQuery($sql);
echo $csv_header;
while ($row = dbFetchAssoc($recordset)) {
echo $absinter->parse($csv_detail, $row);
}