diff --git a/app/core/Database.php b/app/core/Database.php index 89e7bb3de2bd2b469110015f2c1d4ef21d498b5e..da9d771170ff462567980b1dd3dba7ad779efd36 100644 --- a/app/core/Database.php +++ b/app/core/Database.php @@ -34,86 +34,7 @@ class Database $this->dbs->exec(Tables::USER_TABLE); $this->dbs->exec(Tables::BOOK_TABLE); $this->dbs->exec(Tables::INVENTORY_TABLE); - // Insert a new user record - $query = "INSERT IGNORE INTO user (id, username, password, admin) VALUES (NULL, :username, :password, :admin)"; - $this->query($query); - - // Bind parameters - $username = "johnys"; // Replace with the actual username - $password = "12345"; // Replace with the actual password - $admin = 1; // Set to 0 for a non-admin user - - $this->statement->bindParam(":username", $username, PDO::PARAM_STR); - $this->statement->bindParam(":password", $password, PDO::PARAM_STR); - $this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL); - - $this->statement->execute(); - - // Insert a new user record - $query = "INSERT IGNORE INTO user (id, username, password, admin) VALUES (NULL, :username, :password, :admin)"; - $this->query($query); - - // Bind parameters - $username = "Corbuz"; // Replace with the actual username - $password = "12345"; // Replace with the actual password - $admin = 0; // Set to 0 for a non-admin user - - $this->statement->bindParam(":username", $username, PDO::PARAM_STR); - $this->statement->bindParam(":password", $password, PDO::PARAM_STR); - $this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL); - - $this->statement->execute(); - - // Insert a new user record - $query = "INSERT IGNORE INTO user (id, username, password, admin) VALUES (NULL, :username, :password, :admin)"; - $this->query($query); - - // Bind parameters - $username = "Kebiri"; // Replace with the actual username - $password = "12345"; // Replace with the actual password - $admin = 0; // Set to 0 for a non-admin user - - $this->statement->bindParam(":username", $username, PDO::PARAM_STR); - $this->statement->bindParam(":password", $password, PDO::PARAM_STR); - $this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL); - - $this->statement->execute(); - // TESTING AUTHOR & BOOK - // Insert two authors (John and Ken) - $authors = ["John", "Ken"]; - foreach ($authors as $authorName) { - $query2 = "INSERT IGNORE INTO author (name) VALUES (:authorName)"; - $this->query($query2); - $this->statement->bindParam(":authorName", $authorName, PDO::PARAM_STR); - $this->statement->execute(); - } - $this->statement->execute(); - - // Insert 5 books, 3 by John and 2 by Ken - $books = [ - ["title" => "Book 1", "content" => "aa", "author_id" => 1, "audio_path" => "audio1.mp3", "image_path" => "image1.jpg", "category" => "Category A"], - ["title" => "Book 2", "content" => "aa", "author_id" => 1, "audio_path" => "audio2.mp3", "image_path" => "image2.jpg", "category" => "Category B"], - ["title" => "Book 3", "content" => "aa", "author_id" => 1, "audio_path" => "audio3.mp3", "image_path" => "image3.jpg", "category" => "Category C"], - ["title" => "Book 4", "content" => "aa", "author_id" => 2, "audio_path" => "audio4.mp3", "image_path" => "image4.jpg", "category" => "Category D"], - ["title" => "Book 5", "content" => "aa", "author_id" => 2, "audio_path" => "audio5.mp3", "image_path" => "image5.jpg", "category" => "Category E"] - ]; - - foreach ($books as $book) { - $query3 = "INSERT IGNORE INTO book (title, content, author_id, audio_path, image_path, category) - VALUES (:title, :content, :author_id, :audio_path, :image_path, :category)"; - $this->query($query3); - $this->statement->bindParam(":title", $book['title'], PDO::PARAM_STR); - $this->statement->bindParam(":content", $book['content'], PDO::PARAM_STR); - $this->statement->bindParam(":author_id", $book['author_id'], PDO::PARAM_INT); - $this->statement->bindParam(":audio_path", $book['audio_path'], PDO::PARAM_STR); - $this->statement->bindParam(":image_path", $book['image_path'], PDO::PARAM_STR); - $this->statement->bindParam(":category", $book['category'], PDO::PARAM_STR); - $this->statement->execute(); - } - - - // Execute the query - $this->statement->execute(); + } catch (PDOException $e) { die($e->getMessage()); }