Music Database Manager

System Error: ".htmlspecialchars($e->getMessage()).""; } ?>
fetchAllRecords($table); echo "
"; echo "

{$table} Records

"; if (!empty($tableData['data'])) { echo "
"; echo ""; // Table header echo ""; foreach ($tableData['columns'] as $column) { echo ""; } echo ""; // Table body echo ""; foreach ($tableData['data'] as $row) { echo ""; foreach ($row as $value) { echo ""; } echo ""; } echo "
".htmlspecialchars($column)."
".htmlspecialchars($value)."
"; } else { echo "

No records found in {$table} table.

"; } echo "
"; } } /** * Renders forms for data modification */ function renderDataModificationForms(): void { $formConfigurations = [ 'artist' => [ 'title' => 'Add New Artist', 'action' => 'addArtist', 'fields' => [ ['name' => 'artist_name', 'type' => 'text', 'label' => 'Artist Name'] ] ], 'album' => [ 'title' => 'Update Album', 'action' => 'updateAlbum', 'fields' => [ ['name' => 'album_id', 'type' => 'number', 'label' => 'Album ID'], ['name' => 'new_name', 'type' => 'text', 'label' => 'New Album Name'] ] ], 'track' => [ 'title' => 'Delete Track', 'action' => 'removeTrack', 'fields' => [ ['name' => 'track_id', 'type' => 'number', 'label' => 'Track ID'] ] ] ]; foreach ($formConfigurations as $formType => $config) { echo "
"; echo "

{$config['title']}

"; echo "
"; foreach ($config['fields'] as $field) { echo "
"; echo ""; echo ""; echo "
"; } echo ""; echo "
"; } } /** * Provides interface for database queries */ function renderDatabaseQueryInterface($dbHandler): void { $predefinedQueries = [ 'Artists Alphabetical' => "SELECT * FROM Artist ORDER BY ArtistName", 'Love-themed Albums' => "SELECT * FROM Album WHERE AlbumName LIKE '%Love%'", 'Artist-Album Relationships' => "SELECT Artist.ArtistName, Album.AlbumName FROM Artist INNER JOIN Album ON Artist.ArtistID = Album.ArtistID", 'Short Tracks' => "SELECT * FROM Track WHERE TrackDuration < '00:03:00' OR TrackName LIKE '%Intro%'", 'Total Track Count' => "SELECT COUNT(*) AS TotalTracks FROM Track" ]; echo "
"; echo "

Database Query Tool

"; // Query selection form echo "
"; $queryIndex = 1; foreach ($predefinedQueries as $label => $sql) { echo "
"; echo ""; echo ""; echo "
"; $queryIndex++; } echo ""; echo "
"; // Process and display query results if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['execute_query'])) { $selectedIndex = (int)$_POST['selected_query']; $queryLabels = array_keys($predefinedQueries); $selectedQuery = $predefinedQueries[$queryLabels[$selectedIndex-1]]; try { $queryResults = $dbHandler->executeQuery($selectedQuery); echo "
"; echo "

Results: {$queryLabels[$selectedIndex-1]}

"; if (!empty($queryResults)) { echo "
"; echo ""; // Table header echo ""; foreach (array_keys($queryResults[0]) as $column) { echo ""; } echo ""; // Table body echo ""; foreach ($queryResults as $row) { echo ""; foreach ($row as $value) { echo ""; } echo ""; } echo "
".htmlspecialchars($column)."
".htmlspecialchars($value)."
"; } else { echo "

No results found for this query.

"; } echo "
"; } catch (Exception $e) { echo "
Query Error: ".htmlspecialchars($e->getMessage())."
"; } } echo "
"; } ?>