From fbfeeb76793c9d686bb144a9807ebf6da81c45e8 Mon Sep 17 00:00:00 2001 From: Malte Schulze Hobeling Date: Wed, 18 Jan 2023 08:39:45 +0100 Subject: [PATCH] trying to resolve conflict --- BancaDati/BancaDati.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 0ad19f9..eb0c5ab 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -44,18 +44,17 @@ class BancaDati { $value = ""; $column = ""; foreach ($values as $col => $v){ - $value .= "'" . $v . "'" . ","; + $value .= $v . ","; $column .= $col . ","; } $value = trim($value, ","); $column = trim($column, ","); - $sql = "INSERT INTO $table ($column) VALUES ($value);"; + $sql = "INSERT INTO $table($column) VALUES ($value);"; try { $sth = $this->pdo->prepare($sql); $sth->execute(); }catch (PDOException $e){ - var_dump($e); die; } } @@ -71,7 +70,7 @@ class BancaDati { public function update(string $table, string $id, array $values){ $value = ""; foreach ($values as $col => $v){ - $value .= $col . "=" . "'" . $v . "'" . ","; + $value .= $col . "=" . $v . ","; } $value = trim($value, ","); @@ -101,16 +100,23 @@ class BancaDati { } } - - public function select(string $table, array $data, array $order = null){ - $where = ""; - foreach ($data as $col => $v) { - if($where != ""){ - $where .= " AND "; + /** + * einheitliche Select Funktion + * @param string $table + * @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden + * @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC" + * @return void + * @author Malte Schulze Hobeling + */ + public function select(string $table, array $where, array $order = null){ + $whereString = ""; + foreach ($where as $col => $v) { + if($whereString != ""){ + $whereString .= " AND "; } - $where .= $col . "=" . "'" . $v . "'"; + $whereString .= $col . " LIKE " . $v; } - $sql = "SELECT * FROM ".$table." WHERE ".$where; + $sql = "SELECT * FROM ".$table." WHERE ".$whereString; if(isset($order["by"])){ $sql .= " ORDER BY ".$order["by"]; } @@ -118,9 +124,8 @@ class BancaDati { $sql .= $order["order"]; } try { - return $this->pdo->query($sql)->fetch(); + return $this->pdo->query($sql); }catch (PDOException $e){ - var_dump($e); die; } }