2022-11-16 13:27:51 +00:00
|
|
|
<?php
|
|
|
|
|
function fetchCats() {
|
2022-11-20 13:20:58 +00:00
|
|
|
$pdo = startDB();
|
2022-11-16 19:17:35 +00:00
|
|
|
$stmt = $pdo->prepare('SELECT * FROM category');
|
2022-11-16 13:27:51 +00:00
|
|
|
$stmt->execute();
|
|
|
|
|
$cats = $stmt->fetchAll();
|
|
|
|
|
|
|
|
|
|
return $cats;
|
2022-11-16 19:00:51 +00:00
|
|
|
}
|
2022-11-19 15:38:26 +00:00
|
|
|
|
|
|
|
|
function adminCheck() {
|
|
|
|
|
if(isset($_SESSION['admin'])) {
|
|
|
|
|
if($_SESSION['admin'] != 'y') {
|
|
|
|
|
echo '<script>window.location.href = "../index.php";</script>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo'<script>window.location.href = "../index.php";</script>';
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-20 13:20:58 +00:00
|
|
|
|
|
|
|
|
function startDB() {
|
|
|
|
|
$server = 'mysql';
|
|
|
|
|
$username = 'student';
|
|
|
|
|
$password = 'student';
|
|
|
|
|
$schema = 'assignment1';
|
|
|
|
|
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
|
|
|
|
return $pdo;
|
|
|
|
|
}
|
2022-11-16 19:00:51 +00:00
|
|
|
?>
|