From a74a9faa72befd1895ae85f53dbf879613fac9df Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 22 Oct 2024 10:58:52 +0200 Subject: [PATCH] Update questionGateway.php --- src/questionGateway.php | 57 +++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/questionGateway.php b/src/questionGateway.php index 77d964e..c0ff31b 100644 --- a/src/questionGateway.php +++ b/src/questionGateway.php @@ -1,6 +1,6 @@ co -> prepare($query); - - return $stmt -> execute([ - ':id_q' => $q -> getIdquestion(), - ':question' => $q -> getQuestion(), - ':answerA' => $q -> getAnswerA(), - ':answerB' => $q -> getAnswerB(), - ':answerC' => $q -> getAnswerC(), - ':answerD' => $q -> getAnswerD(), - ':cAnswer' => $q -> getCAnswer() + + return $this -> co -> executeQuery($query, [ + 'id_q' => array($q -> getIdQuestion(), PDO::PARAM_INT), + 'question' => array($q -> getQuestion(), PDO::PARAM_STR), + 'answerA' => array($q -> getAnswerA(), PDO::PARAM_STR), + 'answerB' => array($q -> getAnswerB(), PDO::PARAM_STR), + 'answerC' => array($q -> getAnswerC(), PDO::PARAM_STR), + 'answerD' => array($q -> getAnswerD(), PDO::PARAM_STR), + 'cAnswer' => array($q -> getAnswerC(), PDO::PARAM_STR) ]); } @@ -46,9 +45,8 @@ class QuestionGateway public function findById(int $id) : ?QuestionEntity { $query = "SELECT * FROM Question WHERE id_question = :id_q"; - $stmt = $this -> co -> prepare($query); - $stmt -> execute([':id' => $id]); - $res = $stmt -> fetch(PDO::FETCH_ASSOC); + $this -> co -> executeQuery($query, ['id_q' => $id]); + $res = $this -> co -> getResults(); if ($res) return new QuestionEntity( @@ -76,9 +74,11 @@ class QuestionGateway SET question = :question 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 WHERE id_question = :id_q "; - $stmt = $this -> co -> prepare($query); - - return $stmt -> execute([ - ':id_q' => $q -> getIdQuestion(), - ':answerA' => $q -> getAnswerA(), - ':answerB' => $q -> getAnswerB(), - ':answerC' => $q -> getAnswerC(), - ':answerD' => $q -> getAnswerD(), - ':cAnswer' => $q -> getCAnswer(), + + return $this -> co -> executeQuery($query, [ + 'id_q' => array($q -> getIdQuestion(), PDO::PARAM_INT), + 'answerA' => array($q -> getAnswerA(), PDO::PARAM_STR), + 'answerB' => array($q -> getAnswerB(), PDO::PARAM_STR), + 'answerC' => array($q -> getAnswerC(), PDO::PARAM_STR), + 'answerD' => array($q -> getAnswerD(), PDO::PARAM_STR), + 'cAnswer' => array($q -> getAnswerC(), PDO::PARAM_STR) ]); } @@ -116,9 +115,8 @@ class QuestionGateway public function delete(int $id) : bool { $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 { $query = "SELECT * FROM Question"; - $stmt = $this -> co -> prepare($query); - $stmt->execute(); - $res = $stmt -> fetchAll(PDO::FETCH_ASSOC); + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); $questions = [];