diff --git a/Controller/EnthaeltController.php b/Controller/EnthaeltController.php index b4e4aba..7739b5d 100644 --- a/Controller/EnthaeltController.php +++ b/Controller/EnthaeltController.php @@ -1,10 +1,10 @@ db->insertEnthaelt($data); return json_encode($result); } + + public function deleteEnthaelt($id){ + $result=$this->db->deleteEnthaelt($id); + return json_encode($result); + } } ?> \ No newline at end of file diff --git a/Controller/InhaltsstoffController.php b/Controller/InhaltsstoffController.php new file mode 100644 index 0000000..45e9c7c --- /dev/null +++ b/Controller/InhaltsstoffController.php @@ -0,0 +1,23 @@ +db->getInhaltsstoff(); + return json_encode($result); + } + + public function insertInhaltsstoff($data){ + $result=$this->db->insertInhaltsstoff($data); + return json_encode($result); + } + + public function deleteInhaltsstoff($id){ + $result=$this->db->deleteInhaltsstoff($id); + return json_encode($result); + } +?> \ No newline at end of file diff --git a/Model/EnthaeltModel.php b/Model/EnthaeltModel.php index f3f4745..a00546d 100644 --- a/Model/EnthaeltModel.php +++ b/Model/EnthaeltModel.php @@ -1,5 +1,5 @@ linkDB(); + $params = array(); + $sql = "DELETE FROM Enthaelt WHERE id=:id"; + $params[":id"] = $id; + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + return true; + } + catch(\PDOExeption $e){ + return false; + } + } } ?> \ No newline at end of file diff --git a/Model/InhaltsstoffModel.php b/Model/InhaltsstoffModel.php new file mode 100644 index 0000000..451cecb --- /dev/null +++ b/Model/InhaltsstoffModel.php @@ -0,0 +1,60 @@ +linkDB(); + $sql = "SELECT * FROM Inhaltsstoff"; + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute(); + } + catch(\PDOExeption $e){ + return false; + } + $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + return $result; + } + + public function insertInhaltsstoff($data){ + $pdo=$this->linkDB(); + $params = array(); + $sql = "INSERT INTO Inhaltsstoff "; + foreach($data as $index=>$value){ + $sql .= "".$index.","; + } + $sql = substr($sql,0,strlen($sql)-1).") VALUES ("; + + foreach($data as $index=>$value){ + $sql .= "':".$index."',"; + $params[":".$index] = $value; + } + + $sql = substr($sql,0,strlen($sql)-1).");"; + + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + return true; + } + catch(\PDOExeption $e){ + return false; + } + } + + public function deleteInhaltsstoff($id){ + $pdo=$this->linkDB(); + $params = array(); + $sql = "DELETE FROM Inhalsstoff WHERE id=:id"; + $params[":id"] = $id; + try{ + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + return true; + } + catch(\PDOExeption $e){ + return false; + } + } +?> \ No newline at end of file