From 067e78d5d64adbf52c911f0f65cdaa7f8156e903 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 20:41:37 +0300 Subject: Added database initialisation to DB model; added a script for watching file changes --- src/index.php | 7 ++++++- src/models/DB.php | 31 +++++++++++++++++++++++++++++++ watch-move-to-www.sh | 14 ++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/models/DB.php create mode 100755 watch-move-to-www.sh diff --git a/src/index.php b/src/index.php index d87d760..86562ab 100644 --- a/src/index.php +++ b/src/index.php @@ -1 +1,6 @@ -

Hello

+

Hello World!

+ diff --git a/src/models/DB.php b/src/models/DB.php new file mode 100644 index 0000000..f6db512 --- /dev/null +++ b/src/models/DB.php @@ -0,0 +1,31 @@ +connection = mysqli_connect(self::$servername, self::$username, self::$password); + + if (!$this->connection) { + die(mysqli_connect_error()); + } + + // Make sure the actual db exists + $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; + + if (!mysqli_query($this->connection, $createDBQuery)) { + die(mysqli_error($this->connection)); + } + + // Make the actual connection to the database + mysqli_select_db($this->connection, self::$dbname); + } + + function __destruct() { + mysqli_close($this->connection); + } +} diff --git a/watch-move-to-www.sh b/watch-move-to-www.sh new file mode 100755 index 0000000..a67bc44 --- /dev/null +++ b/watch-move-to-www.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DEFAULT_DIR="/var/www/devrix-job-board/" + +if [ ! -d "$DEFAULT_DIR" ]; then + -u www-data mkdir $DEFAULT_DIR +fi + +inotifywait -m ./src/ -r -e attrib -e create -e move -e delete | + while read dir action file; do + echo "[`date +"%Y-%m-%d %T"`] Updated folder" + cp -R ./src/. $DEFAULT_DIR + chown -R www-data:www-data $DEFAULT_DIR* + done -- cgit v1.3.1-26-gb76a