コード例 #1
0
ファイル: parser.php プロジェクト: jason-meredith/music
function getAlbumsTable()
{
    $albums = getAlbumId();
    $artists = getArtistsTable();
    $newAlbumList = array();
    for ($x = 0; $x < count($albums); $x++) {
        $albumArtist = $albums[$x]["artist"];
        $albumId = $albums[$x]["albumId"];
        $albumName = $albums[$x]["album"];
        //echo "<br>songArtist: $songArtist <br>";
        foreach ($artists as $artistIdEntry) {
            $artist = $artistIdEntry["artist"];
            $id = $artistIdEntry["id"];
            if ($albumArtist == $artist) {
                //echo "Match<Br>";
                $song[$x]["artist"] = $id;
                //echo $song["artist"] . "<Br>";
                $updatedAlbum = array("albumId" => $albumId, "album" => $albumName, "artist" => $id);
                array_push($newAlbumList, $updatedAlbum);
            }
        }
    }
    return $newAlbumList;
}
コード例 #2
0
<?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"];