From 151b1ab5490d186496c11975e7e5e43e47404c82 Mon Sep 17 00:00:00 2001 From: Malte Schulze Hobeling Date: Thu, 12 Jan 2023 14:05:19 +0100 Subject: [PATCH 1/6] phpdoc --- BancaDati/BancaDati.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 50ab02b..eb0c5ab 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -100,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"]; } -- 2.39.5 From 1d80d93b1d59ac510fe7bade85fc42652c1e8816 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 12 Jan 2023 14:43:28 +0100 Subject: [PATCH 2/6] add: DB auto_increment --- BancaDati.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BancaDati.sql b/BancaDati.sql index 24b16c9..ad83fa4 100644 --- a/BancaDati.sql +++ b/BancaDati.sql @@ -6,7 +6,7 @@ time_zone = "+00:00"; CREATE TABLE `ingredienti` ( /*Zutaten*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `cognome` varchar(200) NOT NULL, /*Name*/ `caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/ `ilPeso` integer(5) NULL, /*Gewicht*/ @@ -16,14 +16,14 @@ CREATE TABLE `ingredienti` CREATE TABLE `folla` ( /*Menge*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `unita` varchar(200) NOT NULL, /*Einheit*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `elenco` ( /*Liste*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `creatore` varchar(200) NOT NULL, /*Ersteller*/ `coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP @@ -31,7 +31,7 @@ CREATE TABLE `elenco` CREATE TABLE `utente` ( /*Benutzer*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `email` varchar(200) NOT NULL, /*Email*/ `parolaDordine` varchar(255) NOT NULL, /*Passwort*/ `nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/ @@ -41,7 +41,7 @@ CREATE TABLE `utente` CREATE TABLE `elencoIngredienti` ( /*Liste_Zutaten*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `ingredientiID` varchar(36) NOT NULL, /*ZutatenID*/ `elencoID` varchar(36) NOT NULL, /*ListeID*/ `follaID` varchar(36) NOT NULL, /*MengeID*/ @@ -50,7 +50,7 @@ CREATE TABLE `elencoIngredienti` CREATE TABLE `utenteElenco` ( /*Benutzer_Liste*/ - `id` varchar(36) NOT NULL, + `id` int auto_increment NOT NULL, `elencoID` varchar(36) NOT NULL, /*ListeID*/ `utenteID` varchar(36) NOT NULL, /*BenutzerID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -- 2.39.5 From 03a42f3ba71a41334a46f805a5e7d0e6c97f5798 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 12 Jan 2023 14:46:46 +0100 Subject: [PATCH 3/6] add: DB primary key update --- BancaDati.sql | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/BancaDati.sql b/BancaDati.sql index ad83fa4..a764acc 100644 --- a/BancaDati.sql +++ b/BancaDati.sql @@ -6,37 +6,41 @@ time_zone = "+00:00"; CREATE TABLE `ingredienti` ( /*Zutaten*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL, `cognome` varchar(200) NOT NULL, /*Name*/ `caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/ `ilPeso` integer(5) NULL, /*Gewicht*/ `prezzo` decimal(4, 2) NOT NULL, /*Preis*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `folla` ( /*Menge*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL, `unita` varchar(200) NOT NULL, /*Einheit*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `elenco` ( /*Liste*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL, `creatore` varchar(200) NOT NULL, /*Ersteller*/ `coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `utente` ( /*Benutzer*/ - `id` int auto_increment NOT NULL, - `email` varchar(200) NOT NULL, /*Email*/ - `parolaDordine` varchar(255) NOT NULL, /*Passwort*/ + `id` int auto_increment NOT NULL, + `email` varchar(200) NOT NULL, /*Email*/ + `parolaDordine` varchar(255) NOT NULL, /*Passwort*/ `nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/ `gettone` varchar(255), /*Token für Session*/ - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `elencoIngredienti` @@ -46,6 +50,7 @@ CREATE TABLE `elencoIngredienti` `elencoID` varchar(36) NOT NULL, /*ListeID*/ `follaID` varchar(36) NOT NULL, /*MengeID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `utenteElenco` @@ -54,20 +59,9 @@ CREATE TABLE `utenteElenco` `elencoID` varchar(36) NOT NULL, /*ListeID*/ `utenteID` varchar(36) NOT NULL, /*BenutzerID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -ALTER TABLE `ingredienti` /*Zutaten*/ - ADD PRIMARY KEY (`id`); - -ALTER TABLE `folla` /*Menge*/ - ADD PRIMARY KEY (`id`); - -ALTER TABLE `elenco` /*Liste*/ - ADD PRIMARY KEY (`id`); - -ALTER TABLE `utente` /*Benutzer*/ - ADD PRIMARY KEY (`id`); - ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/ ADD PRIMARY KEY (`id`), ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/ -- 2.39.5 From c23b77ff0deef7b37064e0f6f4174317c7029c00 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 12 Jan 2023 14:49:58 +0100 Subject: [PATCH 4/6] add: DB primary key update --- BancaDati.sql | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/BancaDati.sql b/BancaDati.sql index a764acc..21bae82 100644 --- a/BancaDati.sql +++ b/BancaDati.sql @@ -6,60 +6,54 @@ time_zone = "+00:00"; CREATE TABLE `ingredienti` ( /*Zutaten*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `cognome` varchar(200) NOT NULL, /*Name*/ `caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/ `ilPeso` integer(5) NULL, /*Gewicht*/ `prezzo` decimal(4, 2) NOT NULL, /*Preis*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `folla` ( /*Menge*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `unita` varchar(200) NOT NULL, /*Einheit*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `elenco` ( /*Liste*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `creatore` varchar(200) NOT NULL, /*Ersteller*/ `coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `utente` ( /*Benutzer*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `email` varchar(200) NOT NULL, /*Email*/ `parolaDordine` varchar(255) NOT NULL, /*Passwort*/ `nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/ `gettone` varchar(255), /*Token für Session*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `elencoIngredienti` ( /*Liste_Zutaten*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `ingredientiID` varchar(36) NOT NULL, /*ZutatenID*/ `elencoID` varchar(36) NOT NULL, /*ListeID*/ `follaID` varchar(36) NOT NULL, /*MengeID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `utenteElenco` ( /*Benutzer_Liste*/ - `id` int auto_increment NOT NULL, + `id` int auto_increment NOT NULL PRIMARY KEY, `elencoID` varchar(36) NOT NULL, /*ListeID*/ `utenteID` varchar(36) NOT NULL, /*BenutzerID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP - PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/ -- 2.39.5 From da0445ccf6284d217abf2c0477920ac8b58c8142 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 12 Jan 2023 14:51:44 +0100 Subject: [PATCH 5/6] add: DB removing ALTER TABLE ADD Primary Key --- BancaDati.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/BancaDati.sql b/BancaDati.sql index 21bae82..4b2d850 100644 --- a/BancaDati.sql +++ b/BancaDati.sql @@ -57,12 +57,10 @@ CREATE TABLE `utenteElenco` ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/ - ADD PRIMARY KEY (`id`), ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/ ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`), /*Liste_Zutaten hat Foreignkey von Liste(id)*/ ADD CONSTRAINT `FK_ElencoIngredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Liste_Zutaten hat Foreignkey von Menge(id)*/ ALTER TABLE `utenteElenco` /*Benutzer_Liste*/ - ADD PRIMARY KEY (`id`), ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/ ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/ -- 2.39.5 From af0d895227677b3f37d2631197c2532fed1fa95c Mon Sep 17 00:00:00 2001 From: Malte Schulze Hobeling Date: Thu, 12 Jan 2023 14:56:50 +0100 Subject: [PATCH 6/6] fixed: foreignkeys --- BancaDati.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BancaDati.sql b/BancaDati.sql index 4b2d850..fc74c0f 100644 --- a/BancaDati.sql +++ b/BancaDati.sql @@ -42,17 +42,17 @@ CREATE TABLE `utente` CREATE TABLE `elencoIngredienti` ( /*Liste_Zutaten*/ `id` int auto_increment NOT NULL PRIMARY KEY, - `ingredientiID` varchar(36) NOT NULL, /*ZutatenID*/ - `elencoID` varchar(36) NOT NULL, /*ListeID*/ - `follaID` varchar(36) NOT NULL, /*MengeID*/ + `ingredientiID` int NOT NULL, /*ZutatenID*/ + `elencoID` int NOT NULL, /*ListeID*/ + `follaID` int NOT NULL, /*MengeID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `utenteElenco` ( /*Benutzer_Liste*/ `id` int auto_increment NOT NULL PRIMARY KEY, - `elencoID` varchar(36) NOT NULL, /*ListeID*/ - `utenteID` varchar(36) NOT NULL, /*BenutzerID*/ + `elencoID` int NOT NULL, /*ListeID*/ + `utenteID` int NOT NULL, /*BenutzerID*/ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 2.39.5