0

私の 2 番目の MySQL クエリが不明な理由で失敗しているようです。$dbLink->query(); から結果を取得する場合のみ、接続時に問題は発生しません。

$photos = getPhotos(getID($_COOKIE[$uname_cookie], $_COOKIE[$passwd_cookie]));

function getID($uName, $passwd) {
    // Just in case, for modularity :P
    include 'misc.php';
    $query = "SELECT ID FROM Users WHERE UserName = '" . $uName . "' AND Password = '" . $passwd . "';";
    $dbLink = new mysqli($host, $user, $pass, $dbname);
    if ($dbLink->connect_errno) {
        echo "Failed to connect to database: " . $dbLink->connect_error;
        return null;
    } else {
        $results = $dbLink->query($query);
        print_r($results->fetch_array());
        $rows = $results->fetch_array();
        return $rows["ID"];
    }
}

function getPhotos($id) {
    // Just in case, for modularity :P
    include 'misc.php';
    $query = "SELECT Location FROM Photos WHERE UserID = " . $id . ";";
    $dbLink = new mysqli($host, $user, $pass, $dbname);
    if ($dbLink->connect_errno) {
        echo "Failed to connect to database: " . $dbLink->connect_error;
        return null;
    } else {
        $results = $dbLink->query($query);
        print_r($results->fetch_array());
        $rows = $results->fetch_array();
        return $rows["ID"];
    }
}

編集: $dbLink を関数 IE getPhotos($id, $dbLink) に渡すことで取得しました

4

1 に答える 1