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

feat: adding initial data examples for testing

parent 6f9bcae6
No related merge requests found
...@@ -47,10 +47,42 @@ class Database ...@@ -47,10 +47,42 @@ class Database
$this->statement->bindParam(":password", $password, PDO::PARAM_STR); $this->statement->bindParam(":password", $password, PDO::PARAM_STR);
$this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL); $this->statement->bindParam(":admin", $admin, PDO::PARAM_BOOL);
// Execute the query // TESTING AUTHOR & BOOK
$this->statement->execute(); // Insert two authors (John and Ken)
} catch (PDOException $e) { $authors = ["John", "Ken"];
die($e->getMessage()); foreach ($authors as $authorName) {
$query = "INSERT IGNORE INTO author (name) VALUES (:authorName)";
$this->query($query);
$this->statement->bindParam(":authorName", $authorName, PDO::PARAM_STR);
$this->statement->execute();
}
// Insert 5 books, 3 by John and 2 by Ken
$books = [
["title" => "Book 1", "author_id" => 1, "audio_path" => "audio1.mp3", "image_path" => "image1.jpg", "category" => "Category A"],
["title" => "Book 2", "author_id" => 1, "audio_path" => "audio2.mp3", "image_path" => "image2.jpg", "category" => "Category B"],
["title" => "Book 3", "author_id" => 1, "audio_path" => "audio3.mp3", "image_path" => "image3.jpg", "category" => "Category C"],
["title" => "Book 4", "author_id" => 2, "audio_path" => "audio4.mp3", "image_path" => "image4.jpg", "category" => "Category D"],
["title" => "Book 5", "author_id" => 2, "audio_path" => "audio5.mp3", "image_path" => "image5.jpg", "category" => "Category E"]
];
foreach ($books as $book) {
$query = "INSERT IGNORE INTO book (title, author_id, audio_path, image_path, category)
VALUES (:title, :author_id, :audio_path, :image_path, :category)";
$this->query($query);
$this->statement->bindParam(":title", $book['title'], 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());
} }
} }
......
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