diff --git a/db/connect.php b/db/connect.php deleted file mode 100644 index 7ab45efbe3d2a27d58375be1bff764bafec8698a..0000000000000000000000000000000000000000 --- a/db/connect.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - $host = 'db'; - $dbname = 'tubes1_WBD'; - $user = 'root'; - $pass = 'your_password'; - - try { - $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); - - // Execute SQL statements from init.sql - $sqlInit = file_get_contents(__DIR__ . '/init.sql'); - $db->exec($sqlInit); - - // echo "Connected successfully and database initialized!<br/>"; - } catch (PDOException $e) { - // echo "Connection failed: " . $e->getMessage(); - } - -?> diff --git a/db/data.php b/db/data.php deleted file mode 100644 index bb66b0015f5b2b02701e9738d4f95243d3ca5447..0000000000000000000000000000000000000000 --- a/db/data.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -include 'connect.php'; - -// Make sure $db is defined and not null -if (isset($db)) { - try { - $db->beginTransaction(); - - // Generate and insert 10000 dummy events with random data - for ($i = 1; $i <= 10000; $i++) { - $eventName = "Event $i"; - $eventStock = rand(1, 10); - $eventPrice = rand(10, 100); - $eventDate = date('Y-m-d H:i:s', strtotime("+$i days")); - $eventLocation = "Location $i"; - $gambar = 'assets/images/' . ($i % 16 + 1) . '.jpg'; - $vid = 'assets/videos/video.mp4'; - - $sqlEvent = "INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) VALUES (?, ?, ?, ?, ?, ?, ?)"; - $stmtEvent = $db->prepare($sqlEvent); - $stmtEvent->execute([$eventName, $eventStock, $eventPrice, $eventDate, $eventLocation, $gambar, $vid]); - - // Generate and insert tickets corresponding to the event's event_stock - for ($j = 1; $j <= $eventStock; $j++) { - $ticketName = "Ticket $j for Event $i"; - $eventId = $i; // Get the last inserted event ID - $sqlTicket = "INSERT INTO tickets (ticket_name, event_id) VALUES (?, ?)"; - $stmtTicket = $db->prepare($sqlTicket); - $stmtTicket->execute([$ticketName, $eventId]); - } - } - - // Insert user data - $userData = [ - ['John Doe', 'john_doe', 'john@example.com', password_hash('password_1', PASSWORD_DEFAULT), 1], - ['Jane Smith', 'jane_smith', 'jane@example.com', password_hash('password_2', PASSWORD_DEFAULT), 0], - ['Admin User', 'admin_user', 'admin@example.com', password_hash('password_3', PASSWORD_DEFAULT), 1], - ['Alice Johnson', 'alice', 'alice@example.com', password_hash('password_4', PASSWORD_DEFAULT), 0], - ['Bob Williams', 'bob', 'bob@example.com', password_hash('password_5', PASSWORD_DEFAULT), 0] - ]; - - $sqlUser = "INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin) VALUES (?, ?, ?, ?, ?)"; - $stmtUser = $db->prepare($sqlUser); - - foreach ($userData as $user) { - $stmtUser->execute($user); - } - - // Commit the transaction - $db->commit(); - - echo "Successfully inserted 10000 dummy events, corresponding tickets, and user data.<br/>"; - } catch (PDOException $e) { - $db->rollBack(); - echo "Error: " . $e->getMessage(); - } -} else { - echo "Error: Database connection not established."; -} - -$db = null; -?> diff --git a/db/init.php b/db/init.php deleted file mode 100644 index d5efdd7fbee4a7978546eb4828d86c6a208c781c..0000000000000000000000000000000000000000 --- a/db/init.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php -include 'connect.php'; - -$dotenvContents = file_get_contents(__DIR__ . '/../.env'); -$dotenvLines = explode("\n", $dotenvContents); - -foreach ($dotenvLines as $line) { - // Skip empty lines and comments - if (!empty($line) && strpos($line, '=') !== false && strpos($line, '#') !== 0) { - list($name, $value) = explode('=', $line, 2); - $_ENV[$name] = $value; - putenv("$name=$value"); - } -} - -error_reporting(E_ALL); -ini_set('display_errors', 1); - - -include 'reset.php'; -include 'data.php'; - -$db = null; - -// echo "Database initialization successful!"; -?> diff --git a/db/init.sql b/db/init.sql deleted file mode 100644 index 0beaedfc29604f9454f333b3a4411b5108553768..0000000000000000000000000000000000000000 --- a/db/init.sql +++ /dev/null @@ -1,48 +0,0 @@ -CREATE DATABASE IF NOT EXISTS tubes1_WBD; - -USE tubes1_WBD; - -CREATE TABLE IF NOT EXISTS events ( - event_id INT AUTO_INCREMENT PRIMARY KEY, - event_name CHAR(255), - event_stock INT, - event_price INT, - event_date DATETIME, - event_location CHAR(255), - gambar VARCHAR(255), - vid VARCHAR(255) -); - -CREATE TABLE IF NOT EXISTS tickets ( - ticket_id INT AUTO_INCREMENT PRIMARY KEY, - ticket_name CHAR(255), - event_id INT, - FOREIGN KEY (event_id) REFERENCES events(event_id) ON DELETE SET NULL -); - -CREATE TABLE IF NOT EXISTS users ( - user_ID INT AUTO_INCREMENT PRIMARY KEY, - user_name CHAR(255), - username CHAR(255) UNIQUE, - user_email VARCHAR(255) UNIQUE, - user_hashedPass CHAR(255), - isAdmin BOOLEAN -); - -CREATE TABLE IF NOT EXISTS pembelian ( - pembelian_id INT AUTO_INCREMENT PRIMARY KEY, - ticket_id INT, - user_id INT, - pembelian_created_time DATETIME, - FOREIGN KEY (ticket_id) REFERENCES tickets(ticket_id), - FOREIGN KEY (user_id) REFERENCES users(user_ID) ON DELETE SET NULL -); - -CREATE TABLE IF NOT EXISTS subscription ( - creator_id int NOT NULL, - subscriber_id int NOT NULL, - status enum('PENDING','ACCEPTED','REJECTED') NOT NULL DEFAULT 'PENDING', - creator_name char(255) NOT NULL, - PRIMARY KEY (creator_id, subscriber_id), - FOREIGN KEY (subscriber_id) REFERENCES users(user_ID) ON DELETE CASCADE -); \ No newline at end of file diff --git a/db/reset.php b/db/reset.php deleted file mode 100644 index 1e98b7a351e2e637d0fa059e489aad7e4f08635b..0000000000000000000000000000000000000000 --- a/db/reset.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - include 'connect.php'; - - try { - $db->exec("DROP TABLE IF EXISTS pembelian"); - $db->exec("DROP TABLE IF EXISTS tickets"); - $db->exec("DROP TABLE IF EXISTS events"); - $db->exec("DROP TABLE IF EXISTS users"); - - // echo "Successfully reset the database<br/>"; - } catch (PDOException $e) { - // echo "Error: " . $e->getMessage(); - } - $db = null; -?> \ No newline at end of file