SW/panel_admin/includes/film_dao.php

83 lines
2.6 KiB
PHP
Raw Normal View History

2021-04-12 12:26:12 +02:00
<?php
include_once('../assets/php/dao.php');
include_once('film_dto.php');
class FilmDAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Create a new Session.
public function createFilm($id, $tittle, $duration, $language, $description){
2021-04-13 13:50:23 +02:00
$sql = sprintf( "INSERT INTO film(tittle, duration, language, description)
VALUES ('%s', '%d', '%s', '%s')",
$tittle, $duration, $language, $description);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
2021-04-12 12:26:12 +02:00
}
//Returns a query to get the film's data.
public function FilmData($id){
$sql = sprintf( "SELECT * FROM film WHERE id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get All the films.
public function allFilmData(){
$sql = sprintf( "SELECT * FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=mysqli_fetch_array($resul)){
$films[] = $this->loadFilm($fila["id"], $fila["tittle"],$fila["duration"],$fila["language"],$fila["description"]);
}
return $films;
}
//Create a new film Data Transfer Object.
public function loadFilm($id, $tittle, $duration, $language, $description){
return new FilmDTO( $id, $tittle, $duration, $language, $description);
}
/*public function addFilm($films) {
$resul = mysqli_query($this->mysqli, $this->createFilm($film.getId(), $film.getTittle(), $film.getDuration(), $film.getLanguage(), $film.getDescription())) or die ('Error into query database');
return $resul;
}*/
2021-04-12 23:23:55 +02:00
public function deleteFilm($id){
2021-04-13 13:50:23 +02:00
$sql = sprintf( "DELETE FROM film WHERE film.id = '%d' ;",$id);
2021-04-12 23:23:55 +02:00
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
2021-04-13 13:50:23 +02:00
public function editFilm($id, $tittle, $duration, $language,$description){
2021-04-12 23:23:55 +02:00
$sql = sprintf( "UPDATE film
2021-04-13 13:50:23 +02:00
SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s'
WHERE film.id = '%d';",
$tittle,$duration,$language, $description,$id);
2021-04-12 23:23:55 +02:00
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
2021-04-12 12:26:12 +02:00
//Returns a query to get all films tittles.
public function tittleFilmData(){
$sql = sprintf( "SELECT tittle FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
}
?>