Skip to content
Snippets Groups Projects
Commit b0c25b1f authored by Bitha17's avatar Bitha17
Browse files

edit: user dummy data

parent 4ba73c85
Branches
Tags
No related merge requests found
<?php <?php
include 'connect.php'; include 'connect.php';
// Make sure $db is defined and not null // Make sure $db is defined and not null
if (isset($db)) { if (isset($db)) {
try { try {
$sqlEvent = <<<EOF $db->beginTransaction();
// Insert events and tickets as before
$sqlEvent = <<<EOF
INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) VALUES INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) VALUES
('Music Concert', 2, 20, '2023-09-30 10:00:00', 'jakarta', 'assets/images/1.jpg', 'assets/videos/video.mp4'), ('Music Concert', 2, 20, '2023-09-30 10:00:00', 'jakarta', 'assets/images/1.jpg', 'assets/videos/video.mp4'),
('Art Exhibition', 2, 15, '2023-10-05 15:30:00', 'prancis', 'assets/images/2.png', 'assets/videos/video.mp4'), ('Art Exhibition', 2, 15, '2023-10-05 15:30:00', 'prancis', 'assets/images/2.png', 'assets/videos/video.mp4'),
...@@ -27,45 +30,49 @@ ...@@ -27,45 +30,49 @@
('Exhibitor Pass', 5); ('Exhibitor Pass', 5);
EOF; EOF;
$sqlUser = <<<EOF $db->exec($sqlEvent);
INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin) VALUES $db->exec($sqlTicket);
('John Doe', 'john_doe', 'john@example.com', 'hashed_password_1', true),
('Jane Smith', 'jane_smith', 'jane@example.com', 'hashed_password_2', false),
('Admin User', 'admin_user', 'admin@example.com', 'hashed_password_3', true),
('Alice Johnson', 'alice', 'alice@example.com', 'hashed_password_4', false),
('Bob Williams', 'bob', 'bob@example.com', 'hashed_password_5', false);
EOF;
$sqlPembelian = <<<EOF // Dummy user data with hashed passwords
INSERT INTO pembelian (ticket_id, user_id, pembelian_created_time) VALUES $userData = [
(1, 1, '2023-10-01 12:30:00'), ['John Doe', 'john_doe', 'john@example.com', password_hash('password_1', PASSWORD_DEFAULT), 1],
(3, 2, '2023-10-06 16:15:00'), ['Jane Smith', 'jane_smith', 'jane@example.com', password_hash('password_2', PASSWORD_DEFAULT), 0],
(2, 3, '2023-11-15 20:00:00'), ['Admin User', 'admin_user', 'admin@example.com', password_hash('password_3', PASSWORD_DEFAULT), 1],
(5, 4, '2023-12-05 10:45:00'), ['Alice Johnson', 'alice', 'alice@example.com', password_hash('password_4', PASSWORD_DEFAULT), 0],
(8, 5, '2024-01-20 08:30:00'); ['Bob Williams', 'bob', 'bob@example.com', password_hash('password_5', PASSWORD_DEFAULT), 0]
EOF; ];
$db->beginTransaction(); $sqlUser = "INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin) VALUES (?, ?, ?, ?, ?)";
$stmt = $db->prepare($sqlUser);
$db->exec($sqlEvent); foreach ($userData as $user) {
// echo "Successfully inserted dummy data to events table<br/>"; $stmt->execute($user);
}
$db->exec($sqlTicket); $stmt->closeCursor();
// echo "Successfully inserted dummy data to tickets table<br/>";
// $db->exec($sqlUser); // // Insert pembelian data
// echo "Successfully inserted dummy data to users table<br/>"; // $sqlPembelian = <<<EOF
// INSERT INTO pembelian (ticket_id, user_id, pembelian_created_time) VALUES
// (1, 1, '2023-10-01 12:30:00'),
// (3, 2, '2023-10-06 16:15:00'),
// (2, 3, '2023-11-15 20:00:00'),
// (5, 4, '2023-12-05 10:45:00'),
// (8, 5, '2024-01-20 08:30:00');
// EOF;
// $db->exec($sqlPembelian); // $db->exec($sqlPembelian);
// echo "Successfully inserted dummy data to pembelian table<br/>";
// Commit the transaction
$db->commit(); $db->commit();
echo "Successfully inserted dummy data.<br/>";
} catch (PDOException $e) { } catch (PDOException $e) {
$db->rollBack(); $db->rollBack();
// echo "Error: " . $e->getMessage(); echo "Error: " . $e->getMessage();
} }
} else { } else {
// echo "Error: Database connection not established."; echo "Error: Database connection not established.";
} }
$db = null; $db = null;
......
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