added more code examples
This commit is contained in:
parent
a4db6712a4
commit
0513c50b67
18
.idea/dataSources.xml
generated
Normal file
18
.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="postgres@localhost" uuid="d6a94836-907f-44a6-862f-b98acfacd192">
|
||||||
|
<driver-ref>postgresql</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:postgresql://localhost:5432/postgres</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/sqldialects.xml
generated
Normal file
7
.idea/sqldialects.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/sql/createDB.sql" dialect="PostgreSQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/sql/rollbackDB.sql" dialect="PostgreSQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -15,7 +15,6 @@ EXTENSION IF NOT EXISTS "uuid-ossp";
|
|||||||
|
|
||||||
CREATE TABLE autohaendler_stock
|
CREATE TABLE autohaendler_stock
|
||||||
(
|
(
|
||||||
id UUID NOT NULL DEFAULT uuid_generate_v4(),
|
|
||||||
color TEXT NOT NULL,
|
color TEXT NOT NULL,
|
||||||
make TEXT NOT NULL,
|
make TEXT NOT NULL,
|
||||||
model TEXT NOT NULL,
|
model TEXT NOT NULL,
|
||||||
|
|||||||
38
src/backend/example/database_calls/getDatabaseTable.php
Normal file
38
src/backend/example/database_calls/getDatabaseTable.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
$hostname = "hostname/IP";
|
||||||
|
$username = "username";
|
||||||
|
$password = "password";
|
||||||
|
$db_name = "databaseName";
|
||||||
|
$port = "webport";
|
||||||
|
|
||||||
|
$sqlArray = [];
|
||||||
|
|
||||||
|
// get PHP config
|
||||||
|
$root_pfad = $_SERVER["DOCUMENT_ROOT"] . "/core";
|
||||||
|
require_once $root_pfad . "/config/global.inc.php";
|
||||||
|
header("Content-Type: text/html; charset=utf-8");
|
||||||
|
|
||||||
|
// start new connection to database
|
||||||
|
$conn = new mysqli($hostname, $username, $password, $db_name, $port);
|
||||||
|
$conn->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();
|
||||||
16
src/backend/example/database_calls/startAjax.js
Normal file
16
src/backend/example/database_calls/startAjax.js
Normal file
@ -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!")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
11
src/frontend/example/index.html
Normal file
11
src/frontend/example/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Example 1</title>
|
||||||
|
<link rel="stylesheet" href="/src/styles.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user