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(); $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(); $res = $st->fetchAll(PDO::FETCH_ASSOC); return $res; } function subToApi($utclogin, $api) { $today = date("Ymd"); $sql = "INSERT INTO subscribe VALUES ('".$utclogin."',".$api.",TO_DATE('".$today."','YYYYMMDD'))"; $res=$this->conn->exec($sql); } function unsubToApi($utclogin, $api) { $sql = "DELETE FROM subscribe WHERE utclogin='".$utclogin."' AND api=".$api; $res=$this->conn->exec($sql); } }