Update questionGateway.php

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

@ -1,6 +1,6 @@
<?php
require_once("../script/Connection.php");
require_once("../public/script/Connection.php");
require_once("questionEntity.php");
class QuestionGateway
@ -24,16 +24,15 @@ class QuestionGateway
INSERT INTO Question
VALUES(:id_q, :question, :answerA, :answerB, :answerC, :answerD, :cAnswer)
";
$stmt = $this -> 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 = [];

Loading…
Cancel
Save