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.

57 lines
1.4 KiB

<?php
class GatewayChapter
{
private $con;
public function __construct($con)
{
$this->con = $con;
}
public function addChapter($chapter)
{
$query = "insert into Chapters(id,name) values (:id,:name);";
$this->con->executeQuery(
$query,
array(
':id' => array($chapter->getId(), PDO::PARAM_INT),
':name' => array($chapter->getName(), PDO::PARAM_STR)
)
);
}
public function getChapters()
{
$query = "SELECT * FROM Chapters;";
$this->con->executeQuery($query);
$results = $this->con->getResults();
if ($results == NULL) {
return false;
}
$chapters = array();
foreach ($results as $row) {
$chapters[] = new Chapter($row['id'], $row['name']);
}
return $chapters;
}
public function updateChapter($chapter)
{
$query = "UPDATE Chapters SET name = :name WHERE id = :id;";
$this->con->executeQuery(
$query,
array(
':id' => array($chapter->getId(), PDO::PARAM_INT),
':name' => array($chapter->getName(), 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)));
}
}