Example #1
0
function getTrendingArtists()
{
    $artist = array();
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $file = "http://plato.cs.virginia.edu/~ams5da/ListenUp/text/trendingArtists.txt";
    $lines = file($file);
    foreach ($lines as $line) {
        $array = explode("\n", $line);
        array_push($artist, trim($array[0]));
    }
    $stmt = $db_connection->stmt_init();
    $stmt->prepare("SELECT * FROM Artists");
    $stmt->execute();
    $stmt->bind_result($a_id, $a_Name, $top_songs_key, $bio);
    while ($stmt->fetch()) {
        if (in_array($a_id, $artist)) {
            echo '<a id="' . $top_songs_key . '" class="list-group-item"><button onclick="display(this,\'' . $a_Name . '\', \'' . $a_id . '\', \'' . $bio . '\')" id="playSong" class ="btn btn-mini"><i class="fa fa-play"></i></button>' . $a_Name . '</a>';
        }
    }
    $stmt->close();
}
Example #2
0
function bindItems($table, $name1, $name2, $id1, $id2)
{
    $mysqli = new mysqli(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
    $stmt = $mysqli->stmt_init();
    if ($stmt->prepare("INSERT INTO {$table} ({$name1}, {$name2}) VALUES (?,?)")) {
        $stmt->bind_param("ii", $id1, $id2);
        $stmt->execute();
        $stmt->close();
        $mysqli->close();
        return true;
    }
    return false;
}
Example #3
0
 /**
  * Prepares a statement or uses an instance from the cache
  *
  * @param string $strQuery
  *
  * @return mysqli_stmt
  */
 private function getPreparedStatement($strQuery)
 {
     $strName = md5($strQuery);
     if (isset($this->arrStatementsCache[$strName])) {
         return $this->arrStatementsCache[$strName];
     }
     $objStatement = $this->linkDB->stmt_init();
     if (!$objStatement->prepare($strQuery)) {
         $this->strErrorMessage = $objStatement->error;
         return false;
     }
     $this->arrStatementsCache[$strName] = $objStatement;
     return $objStatement;
 }
function deleteSongFromPlaylist($p_id, $s_id)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //DELETE FROM `Contains` WHERE `Contains`.`p_id` = 7 AND `Contains`.`s_id` = \'t55174310\'"?
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("Delete from `Contains` where p_id={$p_id} and s_id='{$s_id}'")) {
        $stmt->bind_param('is', $p_id, $s_id);
        $stmt->execute();
    }
}
 /**
  * Simple function to insert data into the database in preparation
  * @param mysqli $db
  * @param $firstname
  * @param $lastname
  * @param $age
  * @param $createdDate
  * @param $balance
  * @throws Exception
  */
 private function rawRowInsert(mysqli $db, $firstname, $lastname, $age, $createdDate, $balance)
 {
     if (!($statement = $db->stmt_init())) {
         throw new Exception('Error creating prepared statement: ' . $db->error);
     }
     if (!$statement->prepare('INSERT INTO people (firstname, lastname, age, createdDate, balance) VALUES (?, ?, ?, ?, ?)')) {
         throw new Exception('Error preparing insert query: ' . $statement->error);
     }
     if (!$statement->bind_param('ssisd', $firstname, $lastname, $age, $createdDate, $balance)) {
         throw new Exception('Error binding parameters: ' . $statement->error);
     }
     if (!$statement->execute()) {
         throw new Exception('Error executing parameters');
     }
 }
function unsubscribeFromPlaylist($p_id, $username)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //echo "Connection made!";
    // "DELETE FROM `cs4750ams5da`.`Subscribes_to` WHERE `Subscribes_to`.`Username` = \'ams5da\' AND `Subscribes_to`.`p_id` = 2"?
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("Delete FROM Subscribes_to WHERE Username = ? and p_id = ?")) {
        $stmt->bind_param("si", $username, $p_id);
        $stmt->execute();
    }
}
Example #7
0
function updatePlaylistName($p_id, $new_p_name)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("UPDATE `Playlists` SET `p_name`= ? WHERE `p_id` = ?")) {
        $stmt->bind_param("si", $new_p_name, $p_id);
        $stmt->execute();
        //echo $userID;
        while ($stmt->fetch()) {
        }
    }
}
Example #8
0
function getAllSongs($userID)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //original query "select s_id, Title, a_name FROM `Songs` natural join `Performed_by` where Songs.s_id = Performed_by.s_id"
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("select s_id, Title, a_name FROM song_artist_album ORDER BY `song_artist_album`.`Title` ASC")) {
        $stmt->execute();
        $stmt->bind_result($s_id, $title, $name);
        while ($stmt->fetch()) {
            echo "<li id=" . $s_id . " onclick=\"play(this.id)\"><a href=\"javascript:;\">" . $title . " - " . $name . "</a></li>";
        }
    }
}
Example #9
0
 public function insert($table, array $data)
 {
     //create prepare statement, etc. INSERT INTO `people` (`firstname`, `lastname`, `age`, `createdDate`) VALUES (?, ?, ?, ?)
     $keys = array_keys($data);
     $dbColumnName = '(';
     foreach ($keys as $key) {
         $dbColumnName .= '`' . $key . '`, ';
     }
     $dbColumnName = substr($dbColumnName, 0, -2);
     $dbColumnName .= ')';
     $table = 'INSERT INTO `' . $table . '` ' . $dbColumnName;
     $numberOfValues = count($data);
     $values = $this->_createValues($numberOfValues);
     $dataType = $this->_checkTypeOfValues($data);
     $type = '';
     //getting first letter from each of value type
     foreach ($dataType as $word) {
         $letter = substr($word, 0, 1);
         $type .= $letter;
     }
     $dataValues = count($data) >= 1 ? ' VALUES (' . $values . ')' : '';
     $sql = $table . $dataValues;
     //$stmt initialization
     $stmt = self::$_db->stmt_init();
     //prepare statement
     if ($sqlPrepare = $stmt->prepare($sql)) {
         $whereClause = $this->createParameters($data);
         $values = array();
         $v = $whereClause->getValues();
         foreach ($v as &$value) {
             array_push($values, &$value);
         }
         $typeList = $whereClause->getTypeList();
         $functionParams = array_merge(array(&$typeList), $values);
         call_user_func_array(array($stmt, 'bind_param'), $functionParams);
         $result = $stmt->execute();
         if (true === $result) {
             return $stmt->insert_id;
         } else {
             throw new Exception('Error: ' . $stmt->error);
         }
         $stmt->close();
     } else {
         throw new Exception("Error: " . $stmt->error);
     }
 }
Example #10
0
function subscribeToPlaylist($p_id, $username, $p_name)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //echo "Connection made!";
    //SELECT Title, a_name FROM `Contains`NATURAL JOIN Performed_by where Contains.s_id = Performed_by.s_id and Contains.p_id = '7'
    //select Subscribes_to.p_id, Subscribes_to.p_name, Username, al_art_URL from Subscribes_to Join Playlists where Subscribes_to.p_id = Playlists.p_id AND Username = 'ams5da' and Subscribes_to.p_name = 'Work out!!!!' and Subscribes_to.p_id = 5
    //echo $p_name;
    $defaultIcon = "images/default-playlist-artwork.png";
    //First check if user is already subscribed to the playlist
    //Then if not, get the album URL
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT * FROM Subscribes_to WHERE Username = ? and p_id = ? and p_name = ?")) {
        $stmt->bind_param("sis", $username, $p_id, $p_name);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($user, $pid, $pname);
        $stmt->fetch();
        //echo $stmt->num_rows;
        if ($stmt->num_rows == 0) {
            $art_URL;
            if ($stmt->prepare("Select al_art_URL from Playlists WHERE p_id = ?")) {
                $stmt->bind_param("s", $p_id);
                $stmt->execute();
                $stmt->bind_result($artURL);
                while ($stmt->fetch()) {
                    $art_URL = $artURL;
                    if (!isset($art_URL) || trim($art_URL) === '') {
                        $art_URL = $defaultIcon;
                    }
                    //echo $artURL;
                }
            }
            if ($stmt->prepare("INSERT into Subscribes_to(Username, p_id, p_name) VALUES (?, ?, ?)")) {
                $stmt->bind_param("sis", $username, $p_id, $p_name);
                $stmt->execute();
                echo "<div class=\"content-grid\" id=\"" . $p_id . "\"><a href=\"#\" onClick=\"play(" . $p_id . ", '" . addslashes($p_name) . "')\"><img src=\"" . $art_URL . "\" title=\"album-name\" /></a><h3>" . $p_name . "</h3><ul><button type=\"button\" class=\"btn btn-danger btn-sm\" onClick=\"Unsubscribe(" . $p_id . ")\">Unsubscribe</button></ul></div>";
            }
        }
    }
}
 /**
  * @param	DbRequestInterface $request
  * @return	DbReponseInterface
  */
 public function execute(MysqliDriver $driver, DbRequestInterface $request, DbResponseInterface $response)
 {
     $stmt = new PreparedStmt($driver->stmt_init());
     $stmt->prepare($request->getSql());
     if ($stmt->isError()) {
         $error = $stmt->getError();
         $response->addError($error['error-text'], $error['error-nbr']);
         return $response;
     }
     /* normalize and bind parameters */
     if ($request->isValues()) {
         $stmt->organizeParams($request->getValues());
         if ($stmt->isError()) {
             $error = $stmt->getError();
             $response->addError($error['error-text'], $error['error-nbr']);
             return $response;
         }
     }
     $stmt->execute();
     if ($stmt->isError()) {
         $error = $stmt->getError();
         $response->addError($error['error-text'], $error['error-nbr']);
         return $response;
     }
     $isOrganized = $stmt->organizeResults();
     if ($stmt->isError()) {
         $error = $stmt->getError();
         $response->addError($error['error-text'], $error['error-nbr']);
         return $response;
     }
     /* database executed the query successfully and 
      * no results are needed
      */
     if ($isOrganized && !$stmt->isResultset()) {
         return $response;
     }
     $stmt->storeResults();
     $errorStack = $response->getErrorStack();
     $data = $stmt->fetch($errorStack, $request->getCallback());
     if (is_array($data)) {
         $response->setResultSet($data);
     }
     return $response;
 }
Example #12
0
function addSongToPlaylist($songID, $songTitle, $playlistID, $playlistName, $a_Name)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5da', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $songTitle = addslashes($songTitle);
    $playlistName = addslashes($playlistName);
    //INSERT INTO Contains (`p_id`, `s_id`, `p_name`, `Title`) VALUES (7, 't55174310', 'Fav Songs', 'Always In My Head')
    //echo($playlistID . " " . $playlistName . " " . $songID . " " . $songName);
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("Insert into `Contains` (`p_id`, `s_id`, `p_name`, `Title`) VALUES ({$playlistID}, '{$songID}', '{$playlistName}', '{$songTitle}')")) {
        $stmt->bind_param('isss', $songID, $songTitle, $playlistID, $playlistName);
        $stmt->execute();
        //echo("executed");
        echo "<li id=" . $songID . " class=\"list-group-item\"><button id=\"deleteSong\" onclick=\"DeleteSongFromPL(this)\" class = \"btn btn-mini\"><i class=\"fa fa-times\"></i></button> " . $songTitle . " - " . $a_Name . "</li>";
    }
}
Example #13
0
function getLikedSongs($u_id)
{
    $uName = $_SESSION['loggedin'];
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT Title, a_name, s_id FROM `Likes` NATURAL Join `Songs` NATURAL Join `Performed_by` WHERE username = '{$uName}'")) {
        $stmt->bind_param("s", $uName);
        $stmt->execute();
        $stmt->bind_result($title, $name, $s_id);
        while ($stmt->fetch()) {
            //echo($name ." ". $title . "\n");
            echo '<a id="' . $s_id . '" class="list-group-item"><button onclick="play(\'' . $s_id . '\')" id="playSong" class ="btn btn-mini"><i class="fa fa-play"></i></button>' . $title . ' - ' . $name . '</a>';
        }
    }
}
function getSongsInPlaylist($p_id)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //echo "Connection made!";
    //SELECT Title, a_name FROM `Contains`NATURAL JOIN Performed_by where Contains.s_id = Performed_by.s_id and Contains.p_id = '7'
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("select s_id, Title, a_name FROM `Contains` natural join `Performed_by` where Contains.s_id = Performed_by.s_id and Contains.p_id = '{$p_id}'")) {
        $stmt->bind_param("i", $p_id);
        $stmt->execute();
        $stmt->bind_result($s_id, $Title, $name);
        while ($stmt->fetch()) {
            echo "<li id=" . $s_id . " class=\"list-group-item\"><button id=\"deleteSong\" onClick='DeleteSongFromPL(this)' class = \"btn btn-mini\"><i class=\"fa fa-times\"></i></button> " . $Title . " - " . $name . "</li>";
        }
    }
}
Example #15
0
function addSongToLikes($user, $songID, $songName)
{
    //echo ("in php: " . $user . ", " . $songID . ", " . $songName);
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $songName = addslashes($songName);
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("INSERT INTO `Likes`(`Username`, `s_id`, `Title`, `likes?`) VALUES (?,?,?, 1)")) {
        $stmt->bind_param("sss", $user, $songID, $songName);
        $stmt->execute();
        $stmt->bind_result();
        while ($stmt->fetch()) {
            //echo($name ." ". $title . "\n");
            echo "Added " . $songName . " for " . $user;
        }
    }
}
Example #16
0
function getAllPlaylists($userID)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $defaultIcon = "images/default-playlist-artwork.png";
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT * FROM Playlists")) {
        $stmt->execute();
        $stmt->bind_result($p1, $playlistname, $iconURL);
        while ($stmt->fetch()) {
            if (!isset($iconURL) || trim($iconURL) === '') {
                $iconURL = $defaultIcon;
            }
            echo "<div class=\"content-grid\" style=\"width: 10%;\"><a href=\"#\" onClick=\"play(" . $p1 . ", '" . addslashes($playlistname) . "')\"><img src=\"" . $iconURL . "\" title=\"album-name\" /></a><h3>" . $playlistname . "</h3><ul><button id=" . $p1 . " type=\"button\" class=\"btn btn-info btn-sm\" onclick=\"editPlaylist(this.id, '" . addslashes($playlistname) . "')\"><i class=\"fa fa-pencil\"></i> Edit Me</button></ul></div>";
        }
    }
}
Example #17
0
function getSpecificSongs($query)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $query = addslashes($query);
    //SELECT DISTINCT s_id, Title FROM `Songs` where UPPER(Title) like UPPER('%r%')
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT DISTINCT s_id, Title, a_Name FROM Performed_by where UPPER(Title) like UPPER('%{$query}%')")) {
        $stmt->bind_param('s', $query);
        $stmt->execute();
        $stmt->bind_result($s_id, $Title, $a_Name);
        echo "<ul class=\"list-group\">";
        while ($stmt->fetch()) {
            echo '<a id="' . $s_id . '" class="list-group-item"><button onclick="AddSongToPL(this, \'' . addslashes($Title) . '\', \'' . addslashes($a_Name) . '\')" id="addSong" class = "btn btn-mini"><i class="fa fa-plus-circle"></i><button onclick="PlaySong(this)" id="playSong" class ="btn btn-mini"><i class="fa fa-play"></i></button>' . $Title . ' - ' . $a_Name . '<button id="like" onclick="likeSong(this, \'' . addslashes($Title) . '\')" class="btn btn-mini"><i class="fa fa-thumbs-o-up"></i></button></a>';
        }
        echo "</ul>";
    }
}
Example #18
0
function getSongsInPlaylist($p_id)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //echo "Connection made!";
    //SELECT Title, a_name FROM `Contains`NATURAL JOIN Performed_by where Contains.s_id = Performed_by.s_id and Contains.p_id = '7'
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("select s_id, Title, a_name FROM `song_artist_album` natural join `Contains` where song_artist_album.s_id = Contains.s_id and Contains.p_id = '{$p_id}'")) {
        $stmt->bind_param("i", $p_id);
        $stmt->execute();
        $stmt->bind_result($s_id, $title, $name);
        while ($stmt->fetch()) {
            //echo($name ." ". $title . "\n");
            /* echo('<li id="' . $s_id. '" onclick="play(this.id)"><a href="javascript:;">' . $title . ' - ' . $name . ' ' . '</a><button id="like" class="btn btn-mini"><i class="fa fa-thumbs-o-up"></i></button></li><input type="image" src="images/likes.png" id="' . $s_id. '" onClick="likeSong(this, \'' . addslashes($title) . '\')"/>');*/
            echo '<a id="' . $s_id . '" class="list-group-item"><button onclick="play(this)" id="playSong" class ="btn btn-mini"><i class="fa fa-play"></i></button>' . $title . ' - ' . $name . '<button onclick="likeSong(this, \'' . addslashes($title) . '\')" id="like" class="btn btn-mini" ><i class="fa fa-thumbs-o-up"></i></button></a>';
        }
    }
}
Example #19
0
function addPlaylist($p_name)
{
    $uName = $_SESSION['loggedin'];
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $p_name = addslashes($p_name);
    //SELECT Title, a_name FROM `Contains`NATURAL JOIN Performed_by where Contains.s_id = Performed_by.s_id and Contains.p_id = '7'
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("INSERT INTO `Playlists`(`p_name`, `al_art_URL`) VALUES (?, 'images/default-playlist-artwork.png')")) {
        $stmt->bind_param('s', $p_name);
        $stmt->execute();
        //$stmt->bind_result($title, $name, $s_id);
    }
    //CREATED TRIGGER FOR THESE QUERIES INSTEAD
    // if($stmt->prepare("SELECT `p_id` FROM `Playlists` WHERE `p_name` = ?")) {
    //   $stmt->bind_param("s", $p_name);
    //   $stmt->execute();
    //   $stmt->bind_result($p_id);
    //   while($stmt->fetch()) {
    //     echo("2: " . $p_name);
    //   }
    // }
    // if($stmt->prepare("INSERT INTO `Creates`(`Username`, `p_id`, `p_name`) VALUES (?, ?, ?)")) {
    //   $stmt->bind_param('sss', $user, $p_id, $p_name);
    //   $user = $uName;
    //   $stmt->execute();
    //   //$stmt->bind_result($title, $name, $s_id);
    //   while($stmt->fetch()) {
    //     echo("3: " . $p_name);
    //   }
    // }
    if ($stmt->prepare("UPDATE `Creates` SET `Username` = ? WHERE Username = p_id")) {
        $stmt->bind_param('s', $uName);
        $stmt->execute();
        $stmt->bind_result();
    }
}
Example #20
0
function searchForPlaylists($query)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    $query = addslashes($query);
    $defaultArtURL = "images/default-playlist-artwork.png";
    //SELECT DISTINCT * FROM `Playlists` where p_name LIKE '%summer%'
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT DISTINCT * FROM Playlists where UPPER(p_name) like UPPER('%{$query}%') LIMIT 8")) {
        $stmt->bind_param('s', $query);
        $stmt->execute();
        $stmt->bind_result($p_id, $p_name, $art_URL);
        while ($stmt->fetch()) {
            if (!isset($art_URL) || trim($art_URL) === '') {
                $art_URL = $defaultArtURL;
            }
            echo "<div class=\"content-grid\" style=\"width: 22%\"><a href=\"#\" onClick=\"play(" . $p_id . ", '" . addslashes($p_name) . "')\"><img src=\"" . $art_URL . "\" title=\"album-name\" /></a><h3>" . $p_name . "</h3><ul><button type=\"button\"  onClick=\"subscribe(" . $p_id . ", '" . addslashes($p_name) . "')\" class=\"btn btn-success btn-sm\">Subscribe!</button></ul></div>";
        }
    }
}
Example #21
0
function getYourPlaylists($userID)
{
    $db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
    if (mysqli_connect_errno()) {
        echo "Connection Error!";
        return;
    }
    //SELECT * FROM Subscribes_to JOIN Playlists WHERE Subscribes_to.p_id = Playlists.p_id AND Username = 'ams5da'
    $defaultIcon = "images/default-playlist-artwork.png";
    $stmt = $db_connection->stmt_init();
    if ($stmt->prepare("SELECT * FROM Subscribes_to JOIN Playlists WHERE Subscribes_to.p_id = Playlists.p_id AND Username = ?")) {
        $stmt->bind_param("s", $userID);
        $stmt->execute();
        $stmt->bind_result($Username, $p1, $playlistname, $p2, $pl2, $iconURL);
        //echo $userID;
        while ($stmt->fetch()) {
            if (!isset($iconURL) || trim($iconURL) === '') {
                $iconURL = $defaultIcon;
            }
            echo "<div class=\"content-grid\" id=\"" . $p1 . "\"><a href=\"#\" onClick=\"play(" . $p1 . ", '" . addslashes($playlistname) . "')\"><img src=\"" . $iconURL . "\" title=\"album-name\" /></a><h3>" . $playlistname . "</h3><ul><button type=\"button\" class=\"btn btn-danger btn-sm\" onClick=\"Unsubscribe(" . $p1 . ")\">Unsubscribe</button></ul></div>";
        }
    }
}
Example #22
0
$name = htmlspecialchars($_POST['name']);
$username = htmlspecialchars($_POST['username']);
$email = htmlspecialchars($_POST['email']);
$pword = htmlspecialchars($_POST['password']);
//====================================================================
//	ESTABLISH DATABASE CONNECTION
//====================================================================
$db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5da', 'music', 'cs4750ams5da');
if (mysqli_connect_errno()) {
    echo "Connection Error!";
    return;
}
//==========================================
//  CHECK TO SEE IF USERNAME HAS BEEN TAKEN
//==========================================
$stmt = $db_connection->stmt_init();
if ($stmt->prepare("SELECT Username FROM Users WHERE Username = ?")) {
    $stmt->bind_param("s", $username);
    $stmt->execute();
    $stmt->bind_result($uName);
    $stmt->fetch();
    if ($uName != NULL) {
        //echo "<center><h3>The username you selected has already been taken!<center></h3>";
        //header("Refresh:2; URL=http://plato.cs.virginia.edu/~ams5da/ListenUp/index.html");
        echo '<script type="text/javascript">
            alert("The username you selected has already been taken"); 
            window.location.href = "http://plato.cs.virginia.edu/~ams5da/ListenUp/index.html";</script>';
    } else {
        //==========================================
        //  INSERT USER CREDENTIALS INTO DATABASE
        //==========================================
Example #23
0
 $frsquery->execute();
 $frsquery->bind_result($frs_userid, $frs_username, $frsl_limit);
 $temp01 = array();
 while ($frsquery->fetch()) {
     $temp01[] = array($frs_userid, $frs_username, $frsl_limit);
 }
 $frsquery->close();
 foreach ($temp01 as $temp) {
     $frs_userid = $temp[0];
     $frs_username = $temp[1];
     $frsl_limit = $temp[2];
     $time = 30 / $frsl_limit;
     $time = 86400 * $time;
     $oldtime = time() - $time;
     $count = 0;
     $frsquery2 = $rfcdb->stmt_init();
     $frsquery2->prepare("SELECT count(frsc_id) FROM frs_contacts WHERE frsc_userid=? AND frsc_timestamp > ?;");
     $frsquery2->bind_param("ii", $frs_userid, $oldtime);
     $frsquery2->execute();
     $frsquery2->bind_result($count);
     $frsquery2->fetch();
     $frsquery2->close();
     if ($count > 0) {
         echo "Skipping {$frs_username}\n";
         continue;
     }
     $rfc_pool = array();
     $frsquery3 = $rfcdb->stmt_init();
     $timestamp_expire = time();
     $timestamp_expire = $timestamp_expire - 3600 * 24 * 25;
     if ($cat != 'all') {
<?php

$user = $_POST["user"];
$index = $_POST["index"];
$count = 0;
// Create connection
$con = new mysqli("localhost", "fradmin", "people123", "friendrequest");
$stmt = $con->stmt_init();
//Searches by name then username(creates it to be unique
//user, index
$requesterSQL = "SELECT username, name FROM users WHERE username IN (SELECT requester AS username FROM requests WHERE requestee=?) ORDER BY name, username LIMIT ?, 21";
$stmt->prepare($requesterSQL);
$stmt->bind_param('si', $user, $index);
$stmt->execute();
$stmt->bind_result($username, $names);
while ($stmt->fetch()) {
    if ($count < 20) {
        echo $username . "," . $names . ";";
    }
    $count = $count + 1;
}
if ($count != 21) {
    echo "\n";
}
mysqli_close($con);
Example #25
0
function db()
{
    $db = new mysqli('localhost', 'uwksac5_admin', 'qpfrldpqhsowntpdy', 'uwksac5_ksa_1');
    if (mysqli_connect_errno()) {
        die('Connect failed: ' . mysqli_connect_error());
    }
    $stmt = $db->stmt_init();
    if ($stmt->prepare("SET names utf8")) {
        $stmt->execute();
        $stmt->close();
    }
    return $db;
}
<?php

$db = new mysqli($_SERVER['DB_HOST'], $_SERVER['DB_USER'], $_SERVER['DB_PASS'], $_SERVER['DB_NAME']);
$request = end(explode('/', rtrim(strtolower($_SERVER[REQUEST_URI]), '/')));
$components = explode(":", $request, 2);
$link = trim($components[0]);
if (count($components) > 1) {
    $campaign = $components[1];
} else {
    $campaign = "";
}
$query = $db->stmt_init();
$query->prepare("SELECT id, target, utm FROM links WHERE short_link like ?");
$query->bind_param('s', $link);
$query->execute();
$query->store_result();
if ($query->num_rows == 0) {
    $target = "http://www.fi.ncsu.edu";
    $id = -1;
    $utm = 1;
} else {
    $query->bind_result($id, $target, $utm);
    $query->fetch();
}
$query->close();
if ($utm == 1) {
    $target_array = array();
    $target_query = parse_url($target, PHP_URL_QUERY);
    parse_str($target_query, $target_array);
    $target_array['utm_source'] = 'fi';
    $target_array['utm_medium'] = 'filinks';
Example #27
0
 $error = '<div class="alert alert-danger" role="alert"><b>Login Error:</b> Please enter a valid username and password.</div>';
 // Required Database Information
 $dbHost = 'localhost';
 $dbUsername = 'gpcorser';
 $dbUserPassword = 'remember';
 $dbName = 'gpcorser';
 // Entered user information
 $uname = $_POST['username'];
 $pass = $_POST['password'];
 // Session Information
 $dataEmail = "";
 $dataPerId = "";
 // Create a mysqli object
 $mysqli = new mysqli($dbHost, $dbUsername, $dbUserPassword, $dbName);
 // Init statement
 $stmt = $mysqli->stmt_init();
 // Create query
 $sql = "SELECT per_email, per_id FROM persons2 \r\n\t\t    WHERE per_email = ? AND per_password = ?";
 if ($stmt = $mysqli->prepare($sql)) {
     // Bind params
     $stmt->bind_param('ss', $uname, $pass);
     // Execute statement
     if ($stmt->execute()) {
         // Bind query result to variables
         $stmt->bind_result($dataEmail, $dataPerId);
         // Fetch the statement
         if ($stmt->fetch()) {
             // Set SESSION variable
             $_SESSION['email'] = $dataEmail;
             $_SESSION['per_id'] = $dataPerId;
             // Close statement and mysqli object
Example #28
0
 /**
  * Special handling for mysqli query().
  *
  * @param string|Select $sql The SQL statement with placeholders.
  * @param array $bind An array of data to bind to the placeholders.
  * @return \mysqli_result
  * @throws \mysqli_sql_exception.
  */
 public function queryBind($sql, $bind = array())
 {
     //try {省略throw-catch-rethrow块,直接抛出\mysqli_sql_exception
     // connect to the database if needed
     if (!$this->_isConnected) {
         $this->_connect();
     }
     // make sure $bind to an array;
     // don't use (array) typecasting because
     // because $bind may be a Expr object
     if (!is_array($bind)) {
         $bind = array($bind);
     }
     //将结果缓冲当中的结果集读出来
     $this->flushQueue();
     $stmt = parent::stmt_init();
     // TODO 以后可以派生mysqli_stmt
     $stmt->prepare($sql);
     if ($stmt === false) {
         throw new Exception('Failed in preparing SQL: ' . $sql);
     }
     if (!empty($bind)) {
         $types = '';
         foreach ($bind as $val) {
             switch (gettype($val)) {
                 case 'string':
                     $types .= 's';
                     break;
                 case 'integer':
                     $types .= 'i';
                     break;
                 case 'double':
                     $types .= 'd';
                     break;
                 case 'boolean':
                 case 'object':
                 case 'array':
                 case 'resource':
                 case 'NULL':
                 case "unknown type":
                 default:
                     $types .= 's';
             }
         }
         $stmt->bind_param($types, $bind);
     }
     // 由于取消了Statement,因此将Profiler的控制代码移动到这里
     // 由于所处的程序位置,省略了$qp->start(),简化了$qp->bindParams()的相关代码
     if ($this->_profiler === false) {
         $stmt->execute();
         $result = $stmt->get_result();
     } else {
         $q = $this->_profiler->queryStart($sql);
         $qp = $this->_profiler->getQueryProfile($q);
         if ($qp->hasEnded()) {
             $q = $this->_profiler->queryClone($qp);
             $qp = $this->_profiler->getQueryProfile($q);
         }
         $qp->bindParams($bind);
         $stmt->execute();
         $result = $stmt->get_result();
         $this->_profiler->queryEnd($q);
     }
     return $result;
 }
 /**
  * Prepares a prepared query.
  *
  * @param string $query The query to execute
  * @param array $queryComponents The components of the query to execute
  * @return \mysqli_stmt|object MySQLi statement / DBAL object
  * @internal This method may only be called by \TYPO3\CMS\Core\Database\PreparedStatement
  */
 public function prepare_PREPAREDquery($query, array $queryComponents)
 {
     if (!$this->isConnected) {
         $this->connectDB();
     }
     $stmt = $this->link->stmt_init();
     $success = $stmt->prepare($query);
     if ($this->debugOutput) {
         $this->debug('stmt_execute', $query);
     }
     return $success ? $stmt : null;
 }
Example #30
0
$endtime="2015-09-01 00:00:00";
*/
if (!filter_var($starttime, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\$/s")))) {
    die("invalid starttime");
}
if (!filter_var($endtime, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\$/s")))) {
    die("invalid endtime");
}
/* 已生产	*/
$query = "select count(id) as num from i_mark where created_at>='{$starttime}' and created_at<='{$endtime}';";
$produceresult = $mysqli->query($query);
$produceresultarray = $produceresult->fetch_array();
$result1 = $produceresultarray['num'];
/*已销售 */
$query = "select count(id) from i_mark where sold_at>=? and sold_at<=?";
$stmt2 = $mysqli->stmt_init();
$stmt2->prepare($query);
$stmt2->bind_param('ss', $starttime, $endtime);
$stmt2->execute();
$stmt2->bind_result($result2);
$stmt2->fetch();
$stmt2->close();
/*已损坏 */
$query = "select count(id) from i_mark where damaged_at>=? and damaged_at<=? and status=3";
$stmt3 = $mysqli->stmt_init();
$stmt3->prepare($query);
$stmt3->bind_param('ss', $starttime, $endtime);
$stmt3->execute();
$stmt3->bind_result($result3);
$stmt3->fetch();
$stmt3->close();