<?php
require_once 'Twig/autoload.php';

require_once 'config.php';
require_once 'functions.php';

use Twig\Environment;
use Twig\Loader\FilesystemLoader;

$loader = new FilesystemLoader(__DIR__ . '/templates');
$twig = new Environment($loader);

// --------------

$dbconn = pg_connect($dbconnstring)
	or die(twig_error($twig, 'Kann Verbindung zur Datenbank nicht herstellen.'));

$query = "SELECT id,timestamp FROM tests ORDER BY timestamp DESC";
$result = pg_query($dbconn, $query)
	or die(twig_error($twig, 'Datenbankfehler: ' . pg_last_error()));

$tests = pg_fetch_all($result);
pg_close($dbconn);

echo $twig->render('index.html.twig', [ 'tests' => $tests ]);

?>
