function getSongsTable() { $rawsongs = getSongListing(); $updatedSongsTable = changeArtistToId($rawsongs); $updatedSongsTable = changeAlbumToId($updatedSongsTable, getAlbumsTable()); return $updatedSongsTable; }
<?php include "connect.php"; include "parser.php"; include "header.php"; $artists = getArtistsTable(); $albums = getAlbumsTable(); $songs = getSongsTable(); mysqli_query($connection, "call clear_db();"); mysqli_query($connection, "START TRANSACTION;"); $stmt = $connection->prepare("INSERT INTO ArtistT (artistId, name) VALUES (?, ?);"); foreach ($artists as $artist) { $stmt->bind_param("is", $id, $name); $id = $artist["id"]; $name = $artist["artist"]; $stmt->execute(); } $stmt = $connection->prepare("INSERT INTO AlbumT (albumId, name, artistId) VALUES (?, ?, ?);"); foreach ($albums as $album) { $stmt->bind_param("isi", $id, $name, $artist); $id = $album["albumId"]; $name = $album["album"]; $artist = $album["artist"]; $stmt->execute(); } $stmt = $connection->prepare("INSERT INTO SongT (songId, trackNo, name, artistId, albumId, url) VALUES (?, ?, ?, ?, ?, ?);"); foreach ($songs as $song) { $stmt->bind_param("sisiis", $songId, $trackNo, $name, $artist, $album, $url); $songId = substr(rtrim(base_convert(hash("md5", $url), 16, 32), "0"), 0, 12); $trackNo = $song["trackNo"]; $name = $song["title"];