109 lines
2.4 KiB
PHP
109 lines
2.4 KiB
PHP
<?php
|
|
namespace Src\TableGateways;
|
|
|
|
class CompteurGateway {
|
|
|
|
private $db = null;
|
|
|
|
public function __construct($db)
|
|
{
|
|
$this->db = $db;
|
|
}
|
|
|
|
public function findAll()
|
|
{
|
|
$statement = "
|
|
SELECT
|
|
id, libelle
|
|
FROM
|
|
compteur;
|
|
";
|
|
|
|
try {
|
|
$statement = $this->db->query($statement);
|
|
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);
|
|
return $result;
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function find($id)
|
|
{
|
|
$statement = "
|
|
SELECT
|
|
id, libelle
|
|
FROM
|
|
compteur
|
|
WHERE id = ?;
|
|
";
|
|
|
|
try {
|
|
$statement = $this->db->prepare($statement);
|
|
$statement->execute(array($id));
|
|
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);
|
|
return $result;
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function insert(Array $input)
|
|
{
|
|
$statement = "
|
|
INSERT INTO compteur
|
|
(libelle)
|
|
VALUES
|
|
(:libelle);
|
|
";
|
|
|
|
try {
|
|
$statement = $this->db->prepare($statement);
|
|
$statement->execute(array(
|
|
'libelle' => $input['libelle'],
|
|
));
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function update($id, Array $input)
|
|
{
|
|
$statement = "
|
|
UPDATE compteur
|
|
SET
|
|
libelle = :libelle
|
|
WHERE id = :id;
|
|
";
|
|
|
|
try {
|
|
$statement = $this->db->prepare($statement);
|
|
$statement->execute(array(
|
|
'id' => (int) $id,
|
|
'libelle' => $input['libelle'],
|
|
));
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$statement = "
|
|
DELETE FROM compteur
|
|
WHERE id = :id;
|
|
";
|
|
|
|
try {
|
|
$statement = $this->db->prepare($statement);
|
|
$statement->execute(array('id' => $id));
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|