Ejemplo n.º 1
0
// Create connection
$mysqli = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully <br>";
/** returns an array of the required info
 	@chname is the name of the channel
 	@chowner is the channel owners username
 	@pnum is the number of the post */
function querytoarray($chname, $chowner, $pnum)
{
    global $mysqli;
    $result = $mysqli->query("SELECT pc_username, pc_comment, pc_time FROM post_comments \n\t\t\t\tWHERE pc_chname = \"{$chname}\" AND pc_chowner = \"{$chowner}\" AND pc_number = \"{$pnum}\"\n\t\t\t\tORDER BY pc_time ASC;");
    $rows = array();
    while ($r = mysqli_fetch_assoc($result)) {
        $rows[] = array('user' => $r['pc_username'], 'comment' => $r['pc_comment'], 'time' => $r['pc_time']);
    }
    return $rows;
}
if (!$chname == null && !$chowner == null && !$pnum == null) {
    $comments = querytoarray($chname, $chowner, $pnum);
    print "[" . json_encode($comments) . "]";
} else {
    $comments = "error: some or all of chname chowner and pnum were null";
}
$mysqli->close();
?>

Ejemplo n.º 2
0
if (!$uname == null) {
    /** check if admin */
    $result = $mysqli->query("SELECT a_username FROM admin WHERE a_username = \"{$uname}\";");
    $aname = $result->fetch_assoc();
    $aname = $aname['a_username'];
    if (!$aname == null) {
        $aname = TRUE;
    } else {
        $aname = FALSE;
    }
    /** find subscribed channels */
    $sub = querytoarray("channelfavs", "ch_fav_chname", "ch_fav_chowner", "ch_fav_username");
    /** check private channel subs */
    $prv = querytoarray("private_view_channels", "prv_chname", "prv_chowner", "prv_username");
    /** check moderator status */
    $mod = querytoarray("channelmods", "cm_chname", "cm_chowner", "cm_username");
    /** check owner status */
    //select table_name from information_schema.tables where table_name LIKE '%_okenso_%';
    $result = $mysqli->query("SELECT table_name FROM information_schema.tables WHERE table_name LIKE \"%{$uname}%\";");
    $rows = array();
    while ($r = mysqli_fetch_assoc($result)) {
        $table = $r['table_name'];
        //print $table;
        /** The monstrosity below strips posts_ and _username from the table names.*/
        $rows[] = array('name' => str_replace($uname . "_", '', str_replace("posts_", '', $table)), 'owner' => $uname);
    }
    $own = $rows;
    //SAMPLE str_replace("world","Peter","Hello world!");
    /** check favorite posts */
    $result = $mysqli->query("SELECT ufp_chname, ufp_chowner, ufp_number FROM users_fav_posts WHERE ufp_username = \"{$uname}\";");
    $rows = array();