Esempio n. 1
0
 function kaikkiArtikkelit()
 {
     $sql = "select * from artikkeli";
     if (!($stmt = $this->db->prepare($sql))) {
         $virhe = $this->db->errorInfo();
         throw new PDOException($virhe[2], $virhe[1]);
     }
     if (!$stmt->execute()) {
         $virhe = $stmt->errorInfo();
         if ($virhe[0] == "HY093") {
             $virhe[2] = "Invalid parameter";
         }
         throw new PDOException($virhe[2], $virhe[1]);
     }
     $artikkelit = array();
     while ($row = $stmt->fetchObject()) {
         $artikkeli = new Artikkeli();
         $artikkeli->setTyyppi($row->tyyppi);
         $artikkeli->setOtsikko($row->otsikko);
         $artikkeli->setAlaotsikko($row->alaotsikko);
         $artikkeli->setTeksti($row->teksti);
         $artikkeli->setKirjoittaja($row->kirjoittaja);
         $artikkeli->setPvm($row->pvm);
         $artikkelit[] = array($artikkeli, $row->id);
     }
     $this->lkm = $stmt->rowCount();
     return $artikkelit;
 }