2023-12-06 09:26:20 +01:00
|
|
|
<?php
|
2024-01-14 17:51:11 +01:00
|
|
|
// Getestet von Samuel Wolff
|
2023-12-18 08:45:12 +01:00
|
|
|
|
|
|
|
namespace ppb\Model;
|
|
|
|
|
|
|
|
use ppb\Library\Msg;
|
|
|
|
|
|
|
|
class InhaltsstoffModel extends Database
|
|
|
|
{
|
|
|
|
|
|
|
|
public function getInhaltsstoff()
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-18 08:22:45 +01:00
|
|
|
$sql = "SELECT * FROM Inhaltsstoff";
|
2023-12-18 08:45:12 +01:00
|
|
|
try {
|
2023-12-18 08:22:45 +01:00
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute();
|
2023-12-18 08:45:12 +01:00
|
|
|
} catch (\PDOException $e) {
|
2023-12-18 08:22:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2023-12-18 08:45:12 +01:00
|
|
|
|
|
|
|
public function insertInhaltsstoff($data)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-18 08:22:45 +01:00
|
|
|
$params = array();
|
2024-01-14 17:51:11 +01:00
|
|
|
$sql = "INSERT INTO Inhaltsstoff (";
|
2023-12-18 08:45:12 +01:00
|
|
|
foreach ($data as $index => $value) {
|
|
|
|
$sql .= "" . $index . ",";
|
2023-12-18 08:22:45 +01:00
|
|
|
}
|
2023-12-18 08:45:12 +01:00
|
|
|
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
|
2023-12-18 08:22:45 +01:00
|
|
|
|
2023-12-18 08:45:12 +01:00
|
|
|
foreach ($data as $index => $value) {
|
2024-01-14 17:51:11 +01:00
|
|
|
$sql .= ":" . $index . ",";
|
2023-12-18 08:45:12 +01:00
|
|
|
$params[":" . $index] = $value;
|
2023-12-18 08:22:45 +01:00
|
|
|
}
|
|
|
|
|
2023-12-18 08:45:12 +01:00
|
|
|
$sql = substr($sql, 0, strlen($sql) - 1) . ");";
|
2023-12-18 08:22:45 +01:00
|
|
|
|
2023-12-18 08:45:12 +01:00
|
|
|
try {
|
2023-12-18 08:22:45 +01:00
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
return true;
|
2023-12-18 08:45:12 +01:00
|
|
|
} catch (\PDOException $e) {
|
2024-01-14 17:51:11 +01:00
|
|
|
echo $sql;
|
2023-12-18 08:22:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 08:45:12 +01:00
|
|
|
public function deleteInhaltsstoff($id)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-18 08:22:45 +01:00
|
|
|
$params = array();
|
2024-01-14 17:51:11 +01:00
|
|
|
$sql = "DELETE FROM Inhaltsstoff WHERE id=:id";
|
2023-12-18 08:22:45 +01:00
|
|
|
$params[":id"] = $id;
|
2023-12-18 08:45:12 +01:00
|
|
|
try {
|
2023-12-18 08:22:45 +01:00
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
return true;
|
2023-12-18 08:45:12 +01:00
|
|
|
} catch (\PDOException $e) {
|
2024-01-14 17:51:11 +01:00
|
|
|
echo $sql;
|
2023-12-18 08:22:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-12-06 09:26:20 +01:00
|
|
|
}
|
2023-12-18 08:45:12 +01:00
|
|
|
}
|
2023-12-06 09:26:20 +01:00
|
|
|
?>
|