diff --git a/cgi-bin/uebung09/Database.php b/cgi-bin/uebung09/Database.php new file mode 100644 index 0000000..97b9c42 --- /dev/null +++ b/cgi-bin/uebung09/Database.php @@ -0,0 +1,79 @@ +connection = new mysqli($host, $user, $password, $database); + } + + /** + * Schließt die Verbindung zru Datenbank + */ + public function __destruct() + { + $this->connection->close(); + } + + /** + * Fügt einen Task mit dem Namen $name in die Tabelle tasks ein + * + * @param string $name + * @return bool true, falls Einfügen erfolgreich + */ + public function addTask($name) + { + $statement = $this->connection->prepare("INSERT INTO tasks(name) VALUES(?)"); + $statement->bind_param("s", $name); + return $statement->execute(); + } + + /** + * Löscht den Taks mit der ID $id aus der Tabelle tasks + * + * @param int $id + * @return bool, falls Löschen erfolgreich + */ + public function deleteTask($id) + { + $statement = $this->connection->prepare("DELETE FROM tasks WHERE id = ?"); + $statement->bind_param("i", $id); + return $statement->execute(); + } + + public function getQuestions() + { + $result = $this->connection->query("SELECT * FROM questions"); + + $resultArray = []; + + while ($line = $result->fetch_assoc()) { + array_push($resultArray, $line); + } + + $result->free(); + + return $resultArray; + } + + +} diff --git a/cgi-bin/uebung09/questions-show.php b/cgi-bin/uebung09/questions-show.php new file mode 100644 index 0000000..6b48eca --- /dev/null +++ b/cgi-bin/uebung09/questions-show.php @@ -0,0 +1,38 @@ +Fragen anzeigen +
Frage | +Antwort0 | +Antwort1 | +Antwort2 | ++ | + |
$question->question | "); + echo("$question->answer0 | "); + echo("$question->answer1 | "); + echo("$question->answer2 | "); + echo("$question->solution | "); + echo("