conn = new PDO('pgsql:host=localhost;port=5432;dbname=apisub', $db_user, $db_pass); } catch (PDOException $e) { die('Connection failed: ' . $e->getMessage()); } } function subList(string $utclogin) : array { $sql = 'SELECT * FROM vsubscription WHERE utclogin=:utclogin'; $st = $this->conn->prepare($sql); $st->execute([ 'utclogin' => $utclogin, ]); $res = $st->fetchAll(PDO::FETCH_ASSOC); return $res; } function apiList(string $semester, int $year) : array { $sql = 'SELECT * FROM vApi WHERE semester=:semester AND year=:year'; $st = $this->conn->prepare($sql); $st->execute([ 'semester' => $semester, 'year' => $year, ]); $res = $st->fetchAll(PDO::FETCH_ASSOC); return $res; } function subToApi($utclogin, $api) : bool { $today = date('Ymd'); $sql = 'INSERT INTO subscribe(utclogin, api, subdate) VALUES (:utclogin, :api, :today)'; $st = $this->conn->prepare($sql); $res = $st->execute([ 'utclogin' => $utclogin, 'api' => $api, 'today' => $today, ]); return $res; } function unsubToApi($utclogin, $api) : bool { $sql = 'DELETE FROM subscribe WHERE utclogin=:utclogin AND api=:api'; $st = $this->conn->prepare($sql); $res = $st->execute([ 'utclogin' => $utclogin, 'api' => $api, ]); return $res; } }