コード例 #1
0
    public function create($title, $content, $idAuthor, Category $Category)
    {
        $sCategory = new SCategory($this->db);
        try {
            $sCategory->setTitle($title);
            $sCategory->setContent($content);
            $sCategory->setIdAuthor($idAuthor);
            $sCategory->setCategory($Category);
        } catch (Exception $e) {
            $errors = $e->getMessage();
        }
        if (!isset($err)) {
            $title = $this->db->quote($sCategory->getTitle());
            $content = $this->db->quote($sCategory->getContent());
            $idAuthor = $sCategory->getIdAuthor();
            $idCategory = $sCategory->getidCategory();
            $query = 'INSERT INTO scategory(title, content, id_author, id_category)
						VALUE (' . $title . ',' . $content . ',' . $idAuthor . ', ' . $idCategory . ')';
        }
        $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);
        }
    }