似乎我的第二个 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) 得到它