From 5517fd4b2185b33ade34e68c4f2a1ccd467d4f6b Mon Sep 17 00:00:00 2001 From: Dzejkobik007 Date: Mon, 20 Mar 2023 13:10:24 +0100 Subject: [PATCH] Add php-sqlcont --- wap/php-sqlcont/IDB.php | 60 +++++++++++++++++++++++++++++++++++++++ wap/php-sqlcont/Mysql.php | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 wap/php-sqlcont/IDB.php create mode 100644 wap/php-sqlcont/Mysql.php diff --git a/wap/php-sqlcont/IDB.php b/wap/php-sqlcont/IDB.php new file mode 100644 index 0000000..85372d2 --- /dev/null +++ b/wap/php-sqlcont/IDB.php @@ -0,0 +1,60 @@ +db = $db; + return $this; + } + + function select(string $query): array { + $result = mysqli_query($this->db,$query); + if ( + $result instanceof mysqli_result + && $result->num_rows > 0 + ){ + return mysqli_fetch_all($result, MYSQLI_ASSOC); + } + return []; + } + + function insert(string $table, array $data): bool { + $query = "INSERT INTO `".$table."` VALUES ("; + for($i = 0; $i < sizeof($data); $i++) { + $query .= "'".$data[$i]."', "; + } + $query .= ")"; + $result = mysqli_query($this->db, $query); + return $result ? true : false; + } + + function update(string $table, int $id, array $data): bool { + $query = "INSERT INTO `".$table."` VALUES ("; + for($i = 0; $i < sizeof($data); $i++) { + $query .= "'".$data[$i]."', "; + } + $query .= ")"; + $result = mysqli_query($this->db, $query); + return $result ? true : false; + } + + function delete(string $table, int $id): bool { + $result = mysqli_query($this->db, "DELETE FROM ".$table." WHERE id=".$id); + return $result ? true : false; + } + +} \ No newline at end of file