diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9228fc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/vendor/ +/node_modules/ +*.log +.env +.idea/ +/sql/* diff --git a/app/Config/database.php b/app/Config/database.php new file mode 100644 index 0000000..53a83a0 --- /dev/null +++ b/app/Config/database.php @@ -0,0 +1,20 @@ +conn = null; + try { + $this->conn = new PDO("mysql:host={$this->host};dbname={$this->db_name}", + $this->username, $this->password); + $this->conn->exec("set names utf8"); + } catch (PDOException $exception) { + echo "Connection error: " . $exception->getMessage(); + } + return $this->conn; + } +} diff --git a/app/Controllers/ProjectController.php b/app/Controllers/ProjectController.php new file mode 100644 index 0000000..c03f07e --- /dev/null +++ b/app/Controllers/ProjectController.php @@ -0,0 +1,14 @@ +project = new Project($db); + } + + public function getAllProjects() { + return $this->project->fetchAll(); + } +} diff --git a/app/Models/Project.php b/app/Models/Project.php new file mode 100644 index 0000000..7c156ad --- /dev/null +++ b/app/Models/Project.php @@ -0,0 +1,16 @@ +conn = $db; + } + + public function fetchAll() { + $query = "SELECT * FROM " . $this->table; + $stmt = $this->conn->prepare($query); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..84b8e56 --- /dev/null +++ b/index.php @@ -0,0 +1,5 @@ +getConnection(); +$controller = new ProjectController($db); + +header("Content-Type: application/json"); +echo json_encode($controller->getAllProjects());