diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..63a12b6 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:5432/postgres + + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..7ed6e52 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/sql/createDB.sql b/sql/createDB.sql index 3c52805..c5b57e8 100644 --- a/sql/createDB.sql +++ b/sql/createDB.sql @@ -1,5 +1,5 @@ CREATE -DATABASE autohaendler; + DATABASE autohaendler; \c autohaendler @@ -11,11 +11,10 @@ CREATE TYPE price; CREATE TYPE doors; CREATE -EXTENSION IF NOT EXISTS "uuid-ossp"; + EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE autohaendler_stock ( - id UUID NOT NULL DEFAULT uuid_generate_v4(), color TEXT NOT NULL, make TEXT NOT NULL, model TEXT NOT NULL, diff --git a/src/backend/example/database_calls/getDatabaseTable.php b/src/backend/example/database_calls/getDatabaseTable.php new file mode 100644 index 0000000..cfab334 --- /dev/null +++ b/src/backend/example/database_calls/getDatabaseTable.php @@ -0,0 +1,38 @@ +set_charset("utf8mb4"); +// close connection on error +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// prepare SQL statement and execute on database +$sql = "SELECT * FROM table"; +// get data from database +$result = $conn->query($sql); +$conn->close(); + +// check if result is empty & has more than "0" rows +if (!empty($result) && (int)$result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + $sqlArray[] = $row; + } + echo json_encode($sqlArray); +} else { + echo "0 results"; +} +exit(); diff --git a/src/backend/example/database_calls/startAjax.js b/src/backend/example/database_calls/startAjax.js new file mode 100644 index 0000000..7e97f61 --- /dev/null +++ b/src/backend/example/database_calls/startAjax.js @@ -0,0 +1,16 @@ +$(document).ready(function () { + + // ajax function to call PHP script on webserver + $.ajax({ + type: "POST", // use what "type" is necessary, POST is most common + url: "getDatabaseTable.php", // path to .php file that will be executed + dataType: "json", // return type of the PHP script + success: function (data) { + console.log("successfully called PHP file!") + // implement logic to write json into HTML here + }, + error: function () { + console.log("failed to call PHP file!") + } + }); +}) \ No newline at end of file diff --git a/src/01_counter/app.js b/src/frontend/01_counter/app.js similarity index 100% rename from src/01_counter/app.js rename to src/frontend/01_counter/app.js diff --git a/src/01_counter/index.html b/src/frontend/01_counter/index.html similarity index 100% rename from src/01_counter/index.html rename to src/frontend/01_counter/index.html diff --git a/src/frontend/example/index.html b/src/frontend/example/index.html new file mode 100644 index 0000000..64b999f --- /dev/null +++ b/src/frontend/example/index.html @@ -0,0 +1,11 @@ + + + + + Example 1 + + + + + + \ No newline at end of file