Compare commits
3 Commits
3831fa1ae9
...
e4e447f5a3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4e447f5a3 | ||
|
|
c997fafc93 | ||
|
|
2a38db72a1 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
*.bak
|
||||
10
si/docker-template/Dockerfile
Normal file
10
si/docker-template/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM node:12.18.1
|
||||
ENV NODE_ENV=production
|
||||
|
||||
COPY "src" "/app"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN npm install --production
|
||||
|
||||
CMD [ "node", "app.js" ]
|
||||
11
si/docker-template/docker-compose.yml
Normal file
11
si/docker-template/docker-compose.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
node:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: docker-template
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
1018
si/docker-template/package-lock.json
generated
Normal file
1018
si/docker-template/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
si/docker-template/package.json
Normal file
14
si/docker-template/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "docker-template",
|
||||
"version": "1.0.0",
|
||||
"description": "## Úvod",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
||||
9
si/docker-template/src/app.js
Normal file
9
si/docker-template/src/app.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const port = 80;
|
||||
|
||||
app.use(express.static('public'));
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`App listening on port ${port}`);
|
||||
})
|
||||
12
si/docker-template/src/public/index.html
Normal file
12
si/docker-template/src/public/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Jakub</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Jakub</h1>
|
||||
</body>
|
||||
</html>
|
||||
60
wap/mysql-tabledump/IDB.php
Normal file
60
wap/mysql-tabledump/IDB.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IDB interface
|
||||
* Interface for DB driver and basic I/U/D/S operations.
|
||||
*/
|
||||
interface IDB
|
||||
{
|
||||
/**
|
||||
* Connect to DB on DBMS
|
||||
*
|
||||
* @param string $host hostname
|
||||
* @param string $username username
|
||||
* @param string $password password
|
||||
* @param string $database database name
|
||||
* @return static instance of DB on success
|
||||
*/
|
||||
public function connect(
|
||||
string $host = "",
|
||||
string $username = "",
|
||||
string $password = "",
|
||||
string $database = ""
|
||||
): ?static;
|
||||
|
||||
/**
|
||||
* SELECT rows from table
|
||||
*
|
||||
* @param string $query SQL query SELECT string
|
||||
* @return array result as a associative array, key is attribute name, value is attribute array; empty on error
|
||||
*/
|
||||
function select(string $query): array;
|
||||
|
||||
/**
|
||||
* INSERT record to table
|
||||
*
|
||||
* @param string $table database table name
|
||||
* @param array $data data to insert, key is attribute name, value is attribute value
|
||||
* @return boolean true on success otherwise false
|
||||
*/
|
||||
function insert(string $table, array $data): bool;
|
||||
|
||||
/**
|
||||
* UPDATE record in table
|
||||
*
|
||||
* @param string $table database table name
|
||||
* @param integer $id primary key value for record to update
|
||||
* @param array $data data to update, key is attribute name, value is attribute value
|
||||
* @return boolean true on success otherwise false
|
||||
*/
|
||||
function update(string $table, int $id, array $data): bool;
|
||||
|
||||
/**
|
||||
* DELETE item from table
|
||||
*
|
||||
* @param string $table database table name
|
||||
* @param integer $id primary key value for record to delete
|
||||
* @return boolean true on success otherwise false
|
||||
*/
|
||||
function delete(string $table, int $id): bool;
|
||||
}
|
||||
63
wap/mysql-tabledump/Mysql.php
Normal file
63
wap/mysql-tabledump/Mysql.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
class MySQL implements IDB
|
||||
{
|
||||
private ?mysqli $db;
|
||||
|
||||
public function connect(
|
||||
string $host = "",
|
||||
string $username = "",
|
||||
string $password = "",
|
||||
string $database = ""
|
||||
): ?static {
|
||||
$db = mysqli_connect($host, $username, $password, $database);
|
||||
if ($db === false) {
|
||||
return null;
|
||||
}
|
||||
$this->db = $db;
|
||||
return $this;
|
||||
}
|
||||
|
||||
function select(string $query): array {
|
||||
$result = mysqli_query($this->db,$query);
|
||||
if (
|
||||
$result instanceof mysqli_result
|
||||
&& $result->num_rows > 0
|
||||
){
|
||||
return mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function insert(string $table, array $data): bool {
|
||||
$keys = "(";
|
||||
$values = "(";
|
||||
foreach(array_keys($data) as $key) {
|
||||
$keys .= "'".$key."', ";
|
||||
}
|
||||
foreach($data as $row) {
|
||||
$values .= "'".$row."', ";
|
||||
}
|
||||
$keys .= ")";
|
||||
$values .= ")";
|
||||
$query = "INSERT INTO `".$table."` ".$keys." VALUES ".$values;
|
||||
$result = mysqli_query($this->db, $query);
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
function update(string $table, int $id, array $data): bool {
|
||||
$query = "INSERT INTO `".$table."` VALUES (";
|
||||
for($i = 0; $i < sizeof($data); $i++) {
|
||||
$query .= "'".$data[$i]."', ";
|
||||
}
|
||||
$query .= ")";
|
||||
$result = mysqli_query($this->db, $query);
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
function delete(string $table, int $id): bool {
|
||||
$result = mysqli_query($this->db, "DELETE FROM ".$table." WHERE id=".$id);
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user