public function edit(Category $category) { $query = "Select id, name\n FROM categories WHERE id = ?"; $this->db->query($query, [$category->getId()]); $result = $this->db->row(); if (!$result) { echo 'No such category'; die; } $query = "Select id, name\n FROM categories WHERE name = ?"; $this->db->query($query, [$category->getName()]); $result = $this->db->row(); if ($result) { echo 'The category with this name exists!'; die; } $query = "Update categories SET name = ?\n WHERE id = ?"; $this->db->query($query, [$category->getName(), $category->getId()]); $result = $this->db->row(); return $result; }
public function addCategory(Category $category) { $result = $this->db->prepare("\n\t\t\tINSERT INTO category(name)\n\t\t\tVALUES(?)\n\t\t"); $result->execute([$category->getName()]); }