public function create($title, $content, $idAuthor) { $category = new Category($this->db); try { $category->setTitle($title); $category->setContent($content); $category->setIdAuthor($idAuthor); } catch (Exception $e) { $errors = $e->getMessage(); echo $errors; } if (!isset($err)) { $title = $this->db->quote($category->getTitle()); $content = $this->db->quote($category->getContent()); $idAuthor = $category->getIdAuthor(); $query = 'INSERT INTO category(title, content, idAuthor) VALUE (' . $title . ',' . $content . ',' . $idAuthor . ')'; } $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { throw new Exception('Database error'); } } else { throw new Exception($errors); } }