Newer
Older
<?php declare(strict_types=1);
abstract class Page {
protected mysqli $database;
protected function __construct() {
error_reporting(E_ALL);
$this->database = new mysqli("localhost","root", "","nasa");
// Check connection
if ($this->database->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// set charset to UTF8!!
if (!$this->database->set_charset("utf8")) {
throw new Exception($this->_database->error);
}
}
protected function __destruct() {
protected function generatePageHeader(string $title = "", string $jsScript = ""):void
{
$title = htmlspecialchars($title);
header("Content-type: text/html; charset=UTF-8");
echo <<<EOT
<!DOCTYPE html>
<html lang="de">
<head>
<title>$title</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
EOT;
if (!empty(trim($jsScript)))
echo "<script src=\"$jsScript\"></script>";
echo <<<EOT