conn = $db; } public function read($item_type, $tier_list_id = null) { $query = "SELECT id, title, image_path, ranking, item_type, tier_list_id FROM " . $this->table_name . " WHERE item_type = :item_type"; if ($tier_list_id) { $query .= " AND tier_list_id = :tier_list_id"; } $stmt = $this->conn->prepare($query); $stmt->bindParam(":item_type", $item_type); if ($tier_list_id) { $stmt->bindParam(":tier_list_id", $tier_list_id); } $stmt->execute(); return $stmt; } public function create() { $query = "INSERT INTO " . $this->table_name . " (title, image_path, ranking, item_type, tier_list_id) VALUES (:title, :image_path, :ranking, :item_type, :tier_list_id)"; $stmt = $this->conn->prepare($query); // Sanitize inputs $this->title = htmlspecialchars(strip_tags($this->title)); $this->image_path = htmlspecialchars(strip_tags($this->image_path)); $stmt->bindParam(":title", $this->title); $stmt->bindParam(":image_path", $this->image_path); $stmt->bindParam(":ranking", $this->ranking); $stmt->bindParam(":item_type", $this->item_type); $stmt->bindParam(":tier_list_id", $this->tier_list_id); if($stmt->execute()) { return true; } return false; } public function update() { $query = "UPDATE " . $this->table_name . " SET ranking = :ranking WHERE id = :id"; $stmt = $this->conn->prepare($query); $stmt->bindParam(":ranking", $this->ranking); $stmt->bindParam(":id", $this->id); if($stmt->execute()) { return true; } return false; } } ?>