public function update(SubCategory $subCategory)
 {
     $id = $subCategory->getid();
     $description = $this->db > quote($subCategory->getDescription());
     $name = $this->db > quote(${$subCategory}->getName());
     $image = $this->db > quote($subCategory->getImage());
     $query = "UPDATE subcategory SET name=" . $name . " description=" . $description . " image=" . $image . " WHERE id=" . $id;
     $res = $this->db->query($query);
     if ($res) {
         return $this->findById($id);
     } else {
         throw new Exception("internal server error");
     }
 }
 public function create(Category $category, $name, $description, $img)
 {
     $sub_category = new SubCategory($this->db);
     $errors = array();
     try {
         $sub_category->setCategory($category);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setImg($img);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $idCategory = intval($sub_category->getIdCategory());
         $name = $this->db->quote($sub_category->getName());
         $description = $this->db->quote($sub_category->getDescription());
         $img = $this->db->quote($sub_category->getImg());
         $query = "INSERT INTO sub_category (id_category, name, description, img) VALUES ('" . $idCategory . "', " . $name . ", " . $description . ", " . $img . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 throw new Exception("Internal server error");
             }
         }
     } else {
         return $errors;
     }
 }