From 52c65cea8596524455cc75889e094157caebba56 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sat, 27 May 2023 14:28:06 -0500 Subject: [PATCH] Adding query class --- Libraries/db/query.php | 53 ++++++++++++++++++++++++++++++++++++++++++ api/test.php | 7 ++++-- main.js | 2 +- test_query.php | 10 ++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 Libraries/db/query.php create mode 100755 test_query.php diff --git a/Libraries/db/query.php b/Libraries/db/query.php new file mode 100644 index 0000000..7820cf3 --- /dev/null +++ b/Libraries/db/query.php @@ -0,0 +1,53 @@ +table_name = $table_name; + } + public function set_columns($columns){ + if (is_array($columns)){ + $this->columns_querying = $columns; + } + } + + public function set_limit(int $limit){ + if ($limit > 0){ + $this->limit = $limit; + } + } + + private function get_columns(){ + $column_string=""; + + if (count($this->columns_querying) === 0){ + $column_string="*"; + } else { + $columns = implode(',', $this->columns_querying); + $column_string=$columns; + } + return $column_string; + } + + private function get_limit() { + $modifier=""; + if ($this->limit > 0){ + $modifier=" LIMIT {$this->limit}"; + } + return $modifier; + } + + private function get_where() { + $where = ""; + return $where; + } + + public function get_query_string(){ + $query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_limit()};"; + return $query; + } + +} +?> \ No newline at end of file diff --git a/api/test.php b/api/test.php index 88c5d49..ed4db11 100644 --- a/api/test.php +++ b/api/test.php @@ -1,6 +1,9 @@ Load($db, ""); +echo $table->get_html(); ?> diff --git a/main.js b/main.js index b8ac23a..85b02c8 100644 --- a/main.js +++ b/main.js @@ -50,7 +50,7 @@ function loadCrontab (id){ } function test (){ - url = "/api/crontab_view.php?name=0hourly"; + url = "/api/test.php"; setAreaByUrl(url); } diff --git a/test_query.php b/test_query.php new file mode 100755 index 0000000..a5d65c7 --- /dev/null +++ b/test_query.php @@ -0,0 +1,10 @@ +#!/usr/bin/php + +set_limit(-1); + +echo $query->get_query_string(); +?>