You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/Website/gateways/GatewayChapter.php

91 lines
2.2 KiB

<?php
namespace gateways;
use usages\Connection;
use \PDO;
class GatewayChapter
{
private $con;
public function __construct()
{
global $dns, $user, $pass;
$this->con = new Connection($dns, $user, $pass);
}
public function addChapter($chapter)
{
$query = "insert into chapters(name) values (:name);";
$this->con->executeQuery(
$query,
array(
':name' => array($chapter['name'], PDO::PARAM_STR)
)
);
}
public function getChapters()
{
$query = "SELECT * FROM chapters";
$this->con->executeQuery($query);
$results = $this->con->getResults();
return $results;
}
public function getChapterByID(int $id)
{
$query = "SELECT * FROM chapters WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results = $this->con->getResults();
return $results[0];
}
public function updateChapter($id, $chapter)
{
$query = "UPDATE chapters SET name = :name WHERE id = :id;";
$this->con->executeQuery(
$query,
array(
':id' => array($id, PDO::PARAM_INT),
':name' => array($chapter['name'], PDO::PARAM_STR)
)
);
}
public function deleteChapter($id)
{
$query = "DELETE FROM chapters WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
}
public function verifyChapterByID($id)
{
$query = "SELECT chapters.id FROM chapters WHERE id = :id;";
$this->con->executeQuery(
$query,
array(
':id' => array($id, PDO::PARAM_STR),
)
);
$results = $this->con->getResults();
return $results[0];
}
public function verifyChapterByName($name)
{
$query = "SELECT * FROM chapters WHERE name = :name;";
$this->con->executeQuery(
$query,
array(
':name' => array($name, PDO::PARAM_STR)
)
);
$results = $this->con->getResults();
return $results[0];
}
}