commit 3b343aea586c97334980959610941dba14450e12
Author: Tomáš Pašek <pasek.thomas@gmail.com>
Date:   Sun Mar 14 17:17:22 2021 +0100

    Feature #8268 Ovládací metody databáze

diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..5093ce5
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/../../../../../:\wamp64\www\aswi\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/aswi.iml b/.idea/aswi.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/aswi.iml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..1763e15
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..8f28812
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/aswi.iml" filepath="$PROJECT_DIR$/.idea/aswi.iml" />
+    </modules>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/application/controller/TableController.php b/application/controller/TableController.php
new file mode 100644
index 0000000..d2cfa84
--- /dev/null
+++ b/application/controller/TableController.php
@@ -0,0 +1,12 @@
+<?php
+require "../model/DB.php";
+$DB = new DB();
+
+// (B) SEARCH FOR USERS
+$results = $DB->select(
+    "SELECT * FROM dd_wordform limit 10"
+);
+
+// (C) OUTPUT RESULTS
+$result = json_encode(count($results)==0 ? null : $results);
+echo $result;
\ No newline at end of file
diff --git a/application/model/DB.php b/application/model/DB.php
new file mode 100644
index 0000000..c9a45f5
--- /dev/null
+++ b/application/model/DB.php
@@ -0,0 +1,45 @@
+<?php
+class DB {
+    // (A) CONNECT TO DATABASE
+    public $error = "";
+    private $pdo = null;
+    private $stmt = null;
+    function __construct () {
+        try {
+            $this->pdo = new PDO(
+                "pgsql:host=".DB_HOST.";dbname=".DB_NAME,
+                DB_USER, DB_PASSWORD, [
+                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
+                ]
+            );
+        } catch (Exception $ex) { die($ex->getMessage()); }
+    }
+
+    // (B) CLOSE CONNECTION
+    function __destruct(){
+        if ($this->stmt!==null) { $this->stmt = null; }
+        if ($this->pdo!==null) { $this->pdo = null; }
+    }
+
+    // (C) RUN A SELECT QUERY
+    function select($sql, $cond=null){
+        $result = false;
+        try {
+            $this->stmt = $this->pdo->prepare($sql);
+            $this->stmt->execute($cond);
+            $result = $this->stmt->fetchAll();
+            return $result;
+        } catch (Exception $ex) {
+            $this->error = $ex->getMessage();
+            return false;
+        }
+    }
+}
+
+// (D) DATABASE SETTINGS - CHANGE TO YOUR OWN!
+define('DB_HOST', 'localhost');
+define('DB_NAME', 'dalimil1');
+define('DB_CHARSET', 'utf8');
+define('DB_USER', 'postgres');
+define('DB_PASSWORD', 'a');
\ No newline at end of file
diff --git a/application/view/Index.php b/application/view/Index.php
new file mode 100644
index 0000000..76473cc
--- /dev/null
+++ b/application/view/Index.php
@@ -0,0 +1,33 @@
+<!-- TESTOVACI INDEX-->
+<?
+include "../controller/TableController.php"
+?>
+<script>
+    function doSearch () {
+        // (A1) GET SEARCH TERM
+        var data = new FormData();
+
+        // (A2) AJAX - USE HTTP:// NOT FILE://
+        var xhr = new XMLHttpRequest();
+        xhr.open("POST", "../controller/TableController.php");
+        xhr.onload = function(){
+            let results = document.getElementById("results"),
+                search = this.response;
+            results.innerHTML = "";
+            console.log(search);
+            let parsedJSON = JSON.parse(search);
+            console.log(parsedJSON);
+            if (parsedJSON != null) { for (let s of parsedJSON) {
+                results.innerHTML += "<div>" + s.id + "</div>";
+            }}
+        };
+        xhr.send(data);
+        return false;
+    }
+</script>
+
+<form onsubmit="return doSearch()">
+    <input type="submit" value="Search"/>
+</form>
+
+<div id="results"></div>
\ No newline at end of file
