aboutsummaryrefslogtreecommitdiff
path: root/tests/csv.php
blob: 2618cd03b1529b082297095ffa68165528159845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
 * Cinisis - Isis db reading tool.
 */

// Import Cinisis Library.
require_once '../index.php';

// Get a db instance.
$isis = new CinisisDb();

// Test connection.
if ($isis->db) {
  // Prepare output
  header("Content-type: application/text/x-csv");
  header("Content-Disposition: attachment; filename=export.csv");
	header("Pragma: no-cache");
	header("Expires: 0");

  $rows   = $isis->db->rows();
  $format = $isis->db->format;

  foreach ($format['fields'] as $field) {
    echo $field['name'] .',';
  }

  for ($n=1; $n <= $rows; $n++) {
    $result = $isis->db->read($n);
    // Format output.
    foreach ($format['fields'] as $field) {
      echo $result[$field['name']] .',';
    }
    echo "\n";
  }
}