diff --git a/Controller/InhaltsstoffController.php b/Controller/InhaltsstoffController.php index 45e9c7c..4a02cd1 100644 --- a/Controller/InhaltsstoffController.php +++ b/Controller/InhaltsstoffController.php @@ -1,23 +1,38 @@ db->getInhaltsstoff(); +class InhaltsstoffController +{ + + private $db; + + public function __construct() + { + $this->db = new InhaltsstoffModel(); + } + + + public function getInhaltsstoff() + { + $result = $this->db->getInhaltsstoff(); return json_encode($result); } - public function insertInhaltsstoff($data){ - $result=$this->db->insertInhaltsstoff($data); + public function insertInhaltsstoff($data) + { + $result = $this->db->insertInhaltsstoff($data); return json_encode($result); } - public function deleteInhaltsstoff($id){ - $result=$this->db->deleteInhaltsstoff($id); + public function deleteInhaltsstoff($id) + { + $result = $this->db->deleteInhaltsstoff($id); return json_encode($result); } +} ?> \ No newline at end of file diff --git a/Model/InhaltsstoffModel.php b/Model/InhaltsstoffModel.php index 451cecb..e4e46c8 100644 --- a/Model/InhaltsstoffModel.php +++ b/Model/InhaltsstoffModel.php @@ -1,60 +1,66 @@ linkDB(); + +namespace ppb\Model; + +use ppb\Library\Msg; + +class InhaltsstoffModel extends Database +{ + + public function getInhaltsstoff() + { + $pdo = $this->linkDB(); $sql = "SELECT * FROM Inhaltsstoff"; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute(); - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { return false; } $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); return $result; } - - public function insertInhaltsstoff($data){ - $pdo=$this->linkDB(); + + public function insertInhaltsstoff($data) + { + $pdo = $this->linkDB(); $params = array(); $sql = "INSERT INTO Inhaltsstoff "; - foreach($data as $index=>$value){ - $sql .= "".$index.","; + foreach ($data as $index => $value) { + $sql .= "" . $index . ","; } - $sql = substr($sql,0,strlen($sql)-1).") VALUES ("; + $sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES ("; - foreach($data as $index=>$value){ - $sql .= "':".$index."',"; - $params[":".$index] = $value; + foreach ($data as $index => $value) { + $sql .= "':" . $index . "',"; + $params[":" . $index] = $value; } - $sql = substr($sql,0,strlen($sql)-1).");"; + $sql = substr($sql, 0, strlen($sql) - 1) . ");"; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute($params); return true; - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { return false; } } - public function deleteInhaltsstoff($id){ - $pdo=$this->linkDB(); + public function deleteInhaltsstoff($id) + { + $pdo = $this->linkDB(); $params = array(); $sql = "DELETE FROM Inhalsstoff WHERE id=:id"; $params[":id"] = $id; - try{ + try { $stmt = $pdo->prepare($sql); $stmt->execute($params); return true; - } - catch(\PDOExeption $e){ + } catch (\PDOException $e) { return false; } } +} ?> \ No newline at end of file