Skip to content
Snippets Groups Projects
Commit 6768dc44 authored by Kenneth Dave's avatar Kenneth Dave
Browse files

feat: add data tables and page example for docker

parent 368bafd4
No related merge requests found
Pipeline #59022 failed with stages
in 0 seconds
.env 0 → 100644
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
FROM php:8.0-apache FROM php:8.0-apache
\ No newline at end of file
WORKDIR /var/www/html
COPY index.php /var/www/html
EXPOSE 80
\ No newline at end of file
<?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();
<?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
...@@ -4,3 +4,5 @@ services: ...@@ -4,3 +4,5 @@ services:
image: tubes-1:latest image: tubes-1:latest
ports: ports:
- 8008:80 - 8008:80
<!DOCTYPE html>
<html>
<head>
<title>My Docker Website</title>
</head>
<body>
<h1>Hello from HTML!</h1>
</body>
</html>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment