createTable( 'pengumuman', [ 'id int(3) NOT NULL AUTO_INCREMENT', 'category int(3) NOT NULL', 'created_at date NOT NULL DEFAULT CURRENT_TIMESTAMP', 'valid_at date NOT NULL DEFAULT CURRENT_TIMESTAMP', 'expired_at date NOT NULL', 'creator int(3) NOT NULL', 'edited_at date', 'editor date', 'content varchar(255) NOT NULL', 'status tinyint NOT NULL DEFAULT 1', 'PRIMARY KEY (id)' ] ); // Create table for categories $this->createTable( 'kategori', [ 'id int(3) NOT NULL AUTO_INCREMENT', 'category varchar(20) NOT NULL', 'PRIMARY KEY (id)' ] ); } public function showAll($key = '', $operator = '', $cond = '') { try { $db = static::connectDB(); $sql = "SELECT * FROM pengumuman"; if ($key && $operator && $cond) { $sql .= " WHERE {$key} {$operator} ?"; } $query = $db->prepare($sql); if ($key && $operator && $cond) { $query->bindValue(1, $cond); } if ($query->execute()) { if ($query->rowCount() != 0) { $result = $query->fetchAll(\PDO::FETCH_ASSOC); return $result; } } return false; } catch (PDOException $e) { echo $e->getMessage(); } } public function showSingle($id) { try { $db = static::connectDB(); $sql = "SELECT * FROM pengumuman WHERE id = ?"; $query = $db->prepare($sql); if ($query->execute([$id])) { if ($query->rowCount() === 1) { $result = $query->fetch(\PDO::FETCH_ASSOC); return $result; } } } catch (PDOException $e) { echo $e->getMessage(); } } public function showCategories() { try { $db = static::connectDB(); $sql = "SELECT * FROM kategori"; $query = $db->prepare($sql); if ($query->execute()) { if ($query->rowCount() > 1) { $results = $query->fetchAll(\PDO::FETCH_ASSOC); return $results; } } } catch (PDOException $e) { echo $e->getMessage(); } } }