【发布时间】:2014-06-29 01:40:53
【问题描述】:
这是我如何将图像推送到数据库的代码:
$title = $_REQUEST['title'];
$description = $_REQUEST['description'];
$image = $_REQUEST['image'];
$bdata = addslashes($image);
$query = "insert into Images (title, description, image) values ($title, $description, '$bdata')" or die("Error in the consult.." . mysqli_error($connection));
$result = $connection->query($query);
$connection->close();
我再次检查了数据库,它存储成功。
这是从表中获取数据的代码:
$query = "select * from Images" or die("Error in the consult.." . mysqli_error($connection));
$result = $connection->query($query);
$events = array();
while ($event = $result->fetch_array(MYSQLI_ASSOC)) {
$events[] = $event;
}
header('Content-type: application/json');
echo json_encode($events);
$result->free();
$connection->close();
结果我收到下一个 json:
{
id: "34",
title: "some image",
description: "some description",
image: null
}
如您所见,“图像”字段为空。在phpAdmin中我看到有一个数据。
【问题讨论】:
-
不要使用“SELECT *”。命名您实际想要返回的列。 (否则我们没有机会)