不要重新分配您的阵列。只需像这样使用$result= query->fetch_assoc()
和检索它们:
$upload = $result['uploadr'];
echo $upload;
为了使您的查询可靠地抵御攻击,您应该使用准备好的语句:
$query = "SELECT * FROM files WHERE hash = ?"
if (!$stmt = $db->prepare($query))
{
echo "Prepared Failed: (" . $db->errno . ") " . $db->error;
}
if (!$stmt->bind_param("s", $file))
{
echo "Bind Failed: (" . $db->errno . ") " . $db->error;
}
if (!$stmt->execute())
{
echo "Execution Failed: (" . $db->errno . ") " . $db->error;
}
if (!$results = $stmt->get_results())
{
echo "No Results where found: (" . $db->errno . ") " . $db->error;
}
while($row = $results->fetch_assoc())
{
$upload = $row['uploadr'];
$name = $row['name'];
echo $upload."<br>";
echo $name;
}
$stmt -> close();
$db -> close();