Пример #1
0
    public function create($title, $idAuthor, SCategory $SCategory)
    {
        $topic = new Topic($this->db);
        try {
            $topic->setTitle($title);
            $topic->setIdAuthor($idAuthor);
            $topic->setSCategory($SCategory);
        } catch (Exception $e) {
            $errors = $e->getMessage();
        }
        if (!isset($err)) {
            $title = $this->db->quote($topic->getTitle());
            $idAuthor = $topic->getIdAuthor();
            $idSCategory = $topic->getidSCategory();
            $query = 'INSERT INTO topic(title, id_author, id_scategory)
						VALUE (' . $title . ',' . $idAuthor . ', ' . $idSCategory . ')';
        }
        $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);
        }
    }
Пример #2
0
 public function create(SousRubrique $sous_rubrique, User $user, $title)
 {
     $topic = new Topic($this->db);
     $valide = $topic->setTitle($title);
     if ($valide === true) {
         $valide = $topic->setAuthor($user);
         if ($valide === true) {
             $valide = $topic->setId_Sous_rubrique($sous_rubrique);
             if ($valide === true) {
                 $title = mysqli_real_escape_string($this->db, $topic->getTitle());
                 $id_author = $user->getId();
                 $id_sous_rubrique = $topic->getIdSousRubrique();
                 $query = "INSERT INTO topic (id_sous_rubrique, id_author, title) VALUES('" . $id_sous_rubrique . "', '" . $id_author . "', '" . $title . "')";
                 $res = mysqli_query($this->db, $query);
                 if ($res) {
                     $id = mysqli_insert_id($this->db);
                     if ($id) {
                         return $this->findById($id);
                     } else {
                         return "Internal server error";
                     }
                 } else {
                     echo 'test14';
                     exit;
                     return mysqli_error($this->db);
                 }
             } else {
                 return $valide;
             }
         } else {
             return $valide;
         }
     } else {
         return $valide;
     }
 }