Update film_dao.php

This commit is contained in:
marian1010 2021-04-13 21:45:30 +02:00
parent e716de272f
commit 11ab79854f

View File

@ -1,5 +1,5 @@
<?php <?php
require_once($prefix.'assets/php/dao.php'); require_once('../assets/php/dao.php');
include_once('film_dto.php'); include_once('film_dto.php');
class Film_DAO extends DAO { class Film_DAO extends DAO {
@ -12,14 +12,18 @@
//Methods: //Methods:
//Create a new Session. //Create a new Session.
public function createFilm($id, $tittle, $duration, $language){ public function createFilm($id, $tittle, $duration, $language,$description){
$exist = sprintf( "SELECT * FROM film WHERE tittle = '%s'", $tittle );
$sql = sprintf( "INSERT INTO film( $id, $tittle, $duration, $language) $film =mysqli_query($this->mysqli, $exist) ;
VALUES ( '%d', '%s', '%d', '%s')", if($film.is_null() ||$film["language"]!=$language){
$id, $tittle, $duration, $language); $sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`)
VALUES ( '%d', '%s', '%d', '%s','%s')",
$id, $tittle, $duration, $language,$description);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
}else{
die ('Error into query database film already exist');
}
return $sql; return $sql;
} }
@ -39,10 +43,8 @@
while($fila=mysqli_fetch_array($resul)){ while($fila=mysqli_fetch_array($resul)){
$films[] = $this->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"]); $films[] = $this->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"]);
} }
$resul->free(); $resul->free();
return $films;
return $resul;
} }
//Returns a query to get all films tittles. //Returns a query to get all films tittles.
@ -89,8 +91,8 @@
} }
//Create a new film Data Transfer Object. //Create a new film Data Transfer Object.
public function loadFilm($id, $tittle, $duration, $language){ public function loadFilm($id, $tittle, $duration, $language,$description){
return new FilmDTO( $id, $tittle, $duration, $language); return new Film_DTO( $id, $tittle, $duration, $language,$description);
} }
} }