diff --git a/Controller/BestellungController.php b/Controller/BestellungController.php index 2c9a493..5f74cc0 100644 --- a/Controller/BestellungController.php +++ b/Controller/BestellungController.php @@ -5,7 +5,7 @@ namespace ppb\Controller; use ppb\Library\Msg; -use ppb\Model\GerichtModel; +use ppb\Model\BestellungModel; class BestellungController { 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/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