diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..e8c3c352aa8e241a04eb2643653dd2d9af77db52 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_HOST=db-tubes-1 +MYSQL_DATABASE=tubeswbd +MYSQL_USER=root +MYSQL_PASSWORD=password +MYSQL_PORT=3306 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2e3ddd6d8b2132e3c4b53de7ba0e9ce61e60670a..ac9e46d52890ef0f836d6cb5b236933981f528b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,7 @@ -FROM php:8.0-apache \ No newline at end of file +FROM php:8.0-apache + +WORKDIR /var/www/html + +COPY index.php /var/www/html + +EXPOSE 80 \ No newline at end of file diff --git a/app/Database.php b/app/Database.php new file mode 100644 index 0000000000000000000000000000000000000000..b5d5a6b1a7303423b0dab581d79cb6bed92ec22f --- /dev/null +++ b/app/Database.php @@ -0,0 +1,77 @@ +<?php + +$servername = "localhost"; +$username = "root"; +$password = "password" +$dbname = "tubeswbd" + +// Koneksi +$conn = new mysqli($servername, $username, $password, $dbname); + +// Cek gagal ato ga +if ($conn->connect_error) { + // Nah gagal + die("Connection failed: " . $conn->connect_error); + +} + + +// Query table author +$authorTableQuery = " +CREATE TABLE IF NOT EXISTS author ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, +);" + +if ($conn->query($authorTableQuery) === TRUE) { + echo "Author table created successfully<br>"; +} else { + echo "Error creating author table: " . $conn->error . "<br>"; +} + + +// Query table book +$bookTableQuery = " +CREATE TABLE IF NOT EXISTS book ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + author_id INT, + FOREIGN KEY(author_id) REFERENCES author(id) + +)"; +if ($conn->query($bookTableQuery) === TRUE) { + echo "Book table created successfully<br>"; +} else { + echo "Error creating book table: " . $conn->error . "<br>"; +} + + +// Query table user +$userTableQuery = " +CREATE TABLE IF NOT EXISTS user( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(20) NOT NULL, + password VARCHAR(255) NOT NULL, +)"; +if ($conn->query($userTableQuery) === TRUE) { + echo "User table created successfully<br>"; +} else { + echo "Error creating user table: " . $conn->error . "<br>"; +} +// Query table inventory for bookmark +$inventoryTableQUery = " +CREATE TABLE IF NOT EXISTS inventory ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + book_id INT NOT NULL, + FOREIGN KEY (user_id) REFERNCES user(id), + FOREIGN KEY (book_id) REFERENCES book(id) +)"; +if ($conn->query($inventoryTableQuery) === TRUE) { + echo "Inventory table created successfully<br>"; +} else { + echo "Error creating inventory table: " . $conn->error . "<br>"; +} + + +$conn-close(); diff --git a/app/tables.php b/app/tables.php new file mode 100644 index 0000000000000000000000000000000000000000..876327b1a261b5d61b902070e8a281eabd67181e --- /dev/null +++ b/app/tables.php @@ -0,0 +1,37 @@ +<?php + +class Tables +{ + public const AUTHOR_TABLE = + "CREATE TABLE IF NOT EXISTS author ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL + );"; + public const USER_TABLE = + "CREATE TABLE IF NOT EXISTS user( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(20) NOT NULL, + password VARCHAR(255) NOT NULL, + admin BOOLEAN NOT NULL + );"; + + public const BOOK_TABLE = + "CREATE TABLE IF NOT EXISTS book ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(256) NOT NULL, + author_id INT, + audio_path VARCHAR(256) NOT NULL, + image_path VARCHAR(256) NOT NULL, + FOREIGN KEY(author_id) REFERENCES author(id) + + );"; + + public const INVENTORY_TABLE = + "CREATE TABLE IF NOT EXISTS inventory ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + book_id INT NOT NULL, + FOREIGN KEY (user_id) REFERNCES user(id), + FOREIGN KEY (book_id) REFERENCES book(id) + );"; +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7c5e0aeeb93e6ef1a07efefaf9b94d87a8878aad..dce3572c92a2d5f184985f279300f3ce4b8b876d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,3 +4,5 @@ services: image: tubes-1:latest ports: - 8008:80 + + diff --git a/index.php b/index.php new file mode 100644 index 0000000000000000000000000000000000000000..be8b9caf2bcb43de76e8ff4c12a4cf4d59bbff5f --- /dev/null +++ b/index.php @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> +<head> + <title>My Docker Website</title> +</head> +<body> + <h1>Hello from HTML!</h1> +</body> +</html> \ No newline at end of file