-
Bitha17 authoredb0c25b1f
Forked from
IF3110-2023-01-18 / Tugas Besar 1
23 commits behind the upstream repository.
data.php 3.08 KiB
<?php
include 'connect.php';
// Make sure $db is defined and not null
if (isset($db)) {
try {
$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
('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'),
('Sports Tournament', 2, 40, '2023-11-12 18:45:00', 'italy', 'assets/images/3.jpg', 'assets/videos/video.mp4'),
('Comedy Show', 2, 30, '2023-12-03 20:00:00', 'jakarta', 'assets/images/4.jpg', 'assets/videos/video.mp4'),
('Tech Conference', 2, 60, '2024-01-18 14:15:00', 'ITB', 'assets/images/5.jpg', 'assets/videos/video.mp4');
EOF;
$sqlTicket = <<<EOF
INSERT INTO tickets (ticket_name, event_id) VALUES
('General Admission', 1),
('VIP Pass', 1),
('Standard Ticket', 2),
('Student Discount', 2),
('Early Bird Special', 3),
('Premium Access', 3),
('Weekend Pass', 4),
('Group Discount', 4),
('Conference Pass', 5),
('Exhibitor Pass', 5);
EOF;
$db->exec($sqlEvent);
$db->exec($sqlTicket);
// Dummy user data with hashed passwords
$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 (?, ?, ?, ?, ?)";
$stmt = $db->prepare($sqlUser);
foreach ($userData as $user) {
$stmt->execute($user);
}
$stmt->closeCursor();
// // Insert pembelian data
// $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);
// Commit the transaction
$db->commit();
echo "Successfully inserted dummy data.<br/>";
} catch (PDOException $e) {
$db->rollBack();
echo "Error: " . $e->getMessage();
}
} else {
echo "Error: Database connection not established.";
}
$db = null;
?>