VPR_Schnittstelle/Model/TagesplanModel.php

69 lines
1.6 KiB
PHP
Raw Normal View History

2023-12-20 09:12:15 +01:00
<?php
//Programmiert von: Max Heer, Getestet von: Samuel Wolff
2023-12-20 09:12:15 +01:00
namespace ppb\Model;
2023-12-20 09:12:15 +01:00
use ppb\Library\Msg;
class TagesplanModel extends Database
{
public function getTagesplan()
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$sql = "SELECT * FROM Tagesplan";
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
2023-12-20 09:12:15 +01:00
return false;
}
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
public function insertTagesplan($data)
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$params = array();
$sql = "INSERT INTO Tagesplan (";
foreach ($data as $index => $value) {
$sql .= "" . $index . ",";
2023-12-20 09:12:15 +01:00
}
$sql = substr($sql, 0, strlen($sql) - 1) . ") VALUES (";
2023-12-20 09:12:15 +01:00
foreach ($data as $index => $value) {
$sql .= ":" . $index . ",";
$params[":" . $index] = $value;
2023-12-20 09:12:15 +01:00
}
$sql = substr($sql, 0, strlen($sql) - 1) . ");";
2023-12-20 09:12:15 +01:00
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
echo $sql;
2023-12-20 09:12:15 +01:00
return false;
}
}
public function deleteTagesplan($id)
{
$pdo = $this->linkDB();
2023-12-20 09:12:15 +01:00
$params = array();
$sql = "DELETE FROM Tagesplan WHERE id=:id";
$params[":id"] = $id;
try {
2023-12-20 09:12:15 +01:00
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return true;
} catch (\PDOException $e) {
2023-12-20 09:12:15 +01:00
return false;
}
}
}
2023-12-20 09:12:15 +01:00
?>