Howto convert a database_table to CSV using Absinter class

Recommend this page to a friend!

      Absint PHP Template Engine Trait  >  All threads  >  Howto convert a database_table to...  >  (Un) Subscribe thread alerts  
Subject:Howto convert a database_table to...
Summary:An example to create a quick conversion, like a database_table t
Messages:1
Author:wim niemans
Date:2021-01-07 16:06:09
 

  1. Howto convert a database_table to...   Reply   Report abuse  
Picture of wim niemans 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);
}

 

For more information send a message to info at phpclasses dot org.