Beispiel #1
0
 public function getMoviesFromDb($columnsNames = ["id", "name", "description", "rating"])
 {
     if (is_array($columnsNames) && !empty($columnsNames)) {
         $columns = implode(",", $columnsNames);
         $sqlQuery = "SELECT " . $columns . " FROM movies";
         $conn = parent::getConnection();
         $result = $conn->query($sqlQuery);
         if ($result->num_rows > 0) {
             while ($row = $result->fetch_assoc()) {
                 $movie = new Movie(parent::getConnection());
                 if (array_key_exists("id", $row)) {
                     $movie->setId($row["id"]);
                 }
                 if (array_key_exists("name", $row)) {
                     $movie->setName($row["name"]);
                 }
                 if (array_key_exists("description", $row)) {
                     $movie->setDescription($row["description"]);
                 }
                 if (array_key_exists("rating", $row)) {
                     $movie->setRating($row["rating"]);
                 }
                 $this->setArrayWithMovies($movie);
             }
         }
     }
 }
Beispiel #2
0
<?php

require_once "../classes/Database.php";
require_once "../classes/Movie.php";
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["movie_name"])) {
    $name = htmlentities($_POST["movie_name"]);
    $description = htmlentities($_POST["movie_description"]);
    $rating = $_POST["movie_rating"];
    $db = DATABASE::getInstance();
    $mysqli = $db->getConnection();
    $movie = new Movie($mysqli);
    $movie->setName($name);
    $movie->setDescription($description);
    $movie->setRating($rating);
    $movie->addToDatabase();
    header("location: adminPanel.php");
} else {
    header("location: adminPanel.php");
}