PHP MySQL第二次查询失败

时间:2013-04-10 21:09:31

标签: php mysql

似乎我的第二个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)函数来获取它

1 个答案:

答案 0 :(得分:0)

$query = "SELECT Location FROM Photos WHERE UserID = '" . $id . "';";