Question: i got php codes here for book.php , DatabaseConnection.php , Functions.php and they are working correctly with main.php code below. i am trying to built

i got php codes here for book.php, DatabaseConnection.php, Functions.php and they are working correctly with main.php code below.
i am trying to built a library management system that will addBook, displayBooks and searchBook
Modify below code to allow me to add, view and search fo books on the web application instead of inside the CLI application in php
The escatic of the web application should be moden, therefore add colur to it
book.php
title = $title;
$this->author = $author;
$this->isbn = $isbn;
$this->genre = $genre;
}
// Getter methods for book properties
public function getTitle()
{
return $this->title;
}
public function getAuthor()
{
return $this->author;
}
public function getISBN()
{
return $this->isbn;
}
public function getGenre()
{
return $this->genre;
}
// Method to display book information
public function displayBookInfo()
{
echo "Title: ". $this->title ."
";
echo "Author: ". $this->author ."
";
echo "ISBN: ". $this->isbn ."
";
echo "Genre: ". $this->genre ."
";
}
}
?>
function.php
prepare($sql);
$stmt->execute([
':title' => $book->getTitle(),
':author' => $book->getAuthor(),
':isbn' => $book->getISBN(),
':genre' => $book->getGenre()
]);
echo "Book added successfully.
";
} catch (PDOException $e){
// Handle errors during the insert operation
echo "Error adding book: ". $e->getMessage();
}
}
// Function to display all books from the database
function displayBooks()
{
$pdo = getPDOConnection();
// SQL query to select all books
$sql = "SELECT * FROM books";
try {
$stmt = $pdo->query($sql);
$books = $stmt->fetchAll();
if ($books){
foreach ($books as $book){
// Display each book's details
echo "Title: ". $book['title']."
";
echo "Author: ". $book['author']."
";
echo "ISBN: ". $book['isbn']."
";
echo "Genre: ". $book['genre']."
";
echo "-----------------------------
";
}
} else {
echo "No books found.
";
}
} catch (PDOException $e){
// Handle errors during the select operation
echo "Error displaying books: ". $e->getMessage();
}
}
// Function to search for books by title
function searchBook($title)
{
$pdo = getPDOConnection();
// SQL query to search for books by title using a LIKE clause
$sql = "SELECT * FROM books WHE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!