不要重新分配您的數組。只需使用$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();
並查詢實際上在mysql中返回結果? – jarchuleta
是的,我做了或死(mysqli_error());沒有錯誤;我也在phpMyAdmin中進行了查詢,並返回了結果。 – Criesval
'print_r($ result)'看起來像什麼?那裏的結果? –