From 6dffa09e88473cadf35b73116b7f93db1171666b Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 21 Dec 2022 11:19:40 +0100 Subject: [PATCH] add: insert into --- BancaDati/BancaDati.php | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 0a81b46..d68cc7d 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -29,6 +29,41 @@ class BancaDati { $data[8] = chr(ord($data[8]) & 0x3f | 0x80); return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } + + /** + * Einheitliche Insert Funktion + * @param string $table + * @param array $values + * @return void + * author Simon Bock + */ + public function insert(string $table, array $values){ + $value = ""; + $column = ""; + foreach ($values as $col => $v){ + $value .= $v . ","; + $column .= $col . ","; + } + $value = trim($value, ","); + $column = trim($column, ","); + + $sql = "INSERT INTO $table($column) VALUES ($value);"; + try { + $sth = $this->pdo->prepare($sql); + $sth->execute(); + }catch (\PDOException $e){ + die; + } + } + + /** + * Einheitliche Update Funktion + * @param string $table + * @param string $id + * @param array $values + * @return void + * @author Malte Schulze Hobeling + */ public function update(string $table, string $id, array $values){ $value = ""; foreach ($values as $col => $v){ @@ -44,4 +79,21 @@ class BancaDati { die; } } + + /** + * Einheitliche Delete Funktion + * @param string $table + * @param string $id + * @return void + * @author Malte Schulze Hobeling + */ + public function delete(string $table, string $id){ + $sql = "DELETE FROM " . $table . " WHERE `id` = " . $id . ";"; + try { + $sth = $this->pdo->prepare($sql); + $sth->execute(); + }catch (\PDOException $e){ + die; + } + } } \ No newline at end of file