Update questionGateway.php

pull/19/head
tomivt 6 months ago
parent bc2e79e1c6
commit a74a9faa72

@ -1,6 +1,6 @@
<?php <?php
require_once("../script/Connection.php"); require_once("../public/script/Connection.php");
require_once("questionEntity.php"); require_once("questionEntity.php");
class QuestionGateway class QuestionGateway
@ -24,16 +24,15 @@ class QuestionGateway
INSERT INTO Question INSERT INTO Question
VALUES(:id_q, :question, :answerA, :answerB, :answerC, :answerD, :cAnswer) VALUES(:id_q, :question, :answerA, :answerB, :answerC, :answerD, :cAnswer)
"; ";
$stmt = $this -> co -> prepare($query);
return $this -> co -> executeQuery($query, [
return $stmt -> execute([ 'id_q' => array($q -> getIdQuestion(), PDO::PARAM_INT),
':id_q' => $q -> getIdquestion(), 'question' => array($q -> getQuestion(), PDO::PARAM_STR),
':question' => $q -> getQuestion(), 'answerA' => array($q -> getAnswerA(), PDO::PARAM_STR),
':answerA' => $q -> getAnswerA(), 'answerB' => array($q -> getAnswerB(), PDO::PARAM_STR),
':answerB' => $q -> getAnswerB(), 'answerC' => array($q -> getAnswerC(), PDO::PARAM_STR),
':answerC' => $q -> getAnswerC(), 'answerD' => array($q -> getAnswerD(), PDO::PARAM_STR),
':answerD' => $q -> getAnswerD(), 'cAnswer' => array($q -> getAnswerC(), PDO::PARAM_STR)
':cAnswer' => $q -> getCAnswer()
]); ]);
} }
@ -46,9 +45,8 @@ class QuestionGateway
public function findById(int $id) : ?QuestionEntity public function findById(int $id) : ?QuestionEntity
{ {
$query = "SELECT * FROM Question WHERE id_question = :id_q"; $query = "SELECT * FROM Question WHERE id_question = :id_q";
$stmt = $this -> co -> prepare($query); $this -> co -> executeQuery($query, ['id_q' => $id]);
$stmt -> execute([':id' => $id]); $res = $this -> co -> getResults();
$res = $stmt -> fetch(PDO::FETCH_ASSOC);
if ($res) if ($res)
return new QuestionEntity( return new QuestionEntity(
@ -76,9 +74,11 @@ class QuestionGateway
SET question = :question SET question = :question
WHERE id_question = :id_q WHERE id_question = :id_q
"; ";
$stmt = $this -> co -> prepare($query);
return $stmt -> execute([':question' => $q -> getQuestion()]); return $this -> co -> executeQuery($query, [
'id_q' => array($q -> getIdQuestion(), PDO::PARAM_INT),
'question' => array($q -> getQuestion(), PDO::PARAM_STR)
]);
} }
/** /**
@ -95,15 +95,14 @@ class QuestionGateway
answerC = :answerC, answerD = :answerD, cAnswer = :cAnswer answerC = :answerC, answerD = :answerD, cAnswer = :cAnswer
WHERE id_question = :id_q WHERE id_question = :id_q
"; ";
$stmt = $this -> co -> prepare($query);
return $this -> co -> executeQuery($query, [
return $stmt -> execute([ 'id_q' => array($q -> getIdQuestion(), PDO::PARAM_INT),
':id_q' => $q -> getIdQuestion(), 'answerA' => array($q -> getAnswerA(), PDO::PARAM_STR),
':answerA' => $q -> getAnswerA(), 'answerB' => array($q -> getAnswerB(), PDO::PARAM_STR),
':answerB' => $q -> getAnswerB(), 'answerC' => array($q -> getAnswerC(), PDO::PARAM_STR),
':answerC' => $q -> getAnswerC(), 'answerD' => array($q -> getAnswerD(), PDO::PARAM_STR),
':answerD' => $q -> getAnswerD(), 'cAnswer' => array($q -> getAnswerC(), PDO::PARAM_STR)
':cAnswer' => $q -> getCAnswer(),
]); ]);
} }
@ -116,9 +115,8 @@ class QuestionGateway
public function delete(int $id) : bool public function delete(int $id) : bool
{ {
$query = "DELETE FROM Question WHERE id_question = :id_q"; $query = "DELETE FROM Question WHERE id_question = :id_q";
$stmt = $this -> co -> prepare($query);
return $stmt -> execute([':id_q' => $id]); return $this -> co -> executeQuery($query, ['id_q' => $id]);
} }
/** /**
@ -129,9 +127,8 @@ class QuestionGateway
public function findAll() : array public function findAll() : array
{ {
$query = "SELECT * FROM Question"; $query = "SELECT * FROM Question";
$stmt = $this -> co -> prepare($query); $this -> co -> executeQuery($query);
$stmt->execute(); $res = $this -> co -> getResults();
$res = $stmt -> fetchAll(PDO::FETCH_ASSOC);
$questions = []; $questions = [];

Loading…
Cancel
Save