From bcaf03610aa85168429d89014c5e3974d527c8ec Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Wed, 21 Dec 2022 10:57:49 +0100 Subject: [PATCH] add: update with associative array --- BancaDati/BancaDati.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 75584de..0a81b46 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -29,7 +29,13 @@ 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)); } - public function update(string $table, string $id, string $value){ + public function update(string $table, string $id, array $values){ + $value = ""; + foreach ($values as $col => $v){ + $value .= $col . "=" . $v . ","; + } + $value = trim($value, ","); + $sql = "UPDATE " . $table . " SET " . $value . " WHERE `id` = " . $id . ";"; try { $sth = $this->pdo->prepare($sql);