public function create($name, $description, $img) { $category = new Category($this->db); $errors = array(); try { $category->setName($name); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $category->setDescription($description); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $category->setImg($img); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $name = $this->db->quote($category->getName()); $description = $this->db->quote($category->getDescription()); $img = $this->db->quote($category->getImg()); $query = "INSERT INTO category (name, description, img) VALUES(" . $name . "," . $description . "," . $img . ")"; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { $errors[] = "Category not found"; return $errors; } } else { $errors[] = "Internal server error"; return $errors; } } else { return $errors; } }