-1
我使用json和php来显示数据库的内容,直到我为数据库实现了一个blob值才能存储我的图片,现在当我运行时页面它不显示数据,我使用的代码是波纹管数组在数据库中使用BLOB时不显示内容
library2页
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
function getAllPictures() {
// include the login credentials
include ("loginasdf.php") ;
// connect to the database to get current state
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) { die("Connection failed: " . mysqli_connect_error());
echo "fail"; }
$sql = "SELECT * FROM Pictures" ;
$result = mysqli_query($conn, $sql);
// convert to JSON
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
var_dump($rows);
return json_encode($rows);
}
显示页
<?php
include("library2.php") ;
$picturetxt = getAllPictures() ;
$picturejson = json_decode($picturetxt) ;
$cl = $picturejson;
for ($i=0 ; $i<sizeof($cl) ; $i++) {
echo "<a href=displaycontact2.php?id=" ;
echo $cl[$i] -> id ;
echo ">" ;
echo $cl[$i] -> hname ;
echo "</a><br/>" ;
echo "</a><br/>" ;
echo "ID: ";
echo $cl[$i] -> ID;
echo "<br/>";
echo "Name: ";
echo $cl[$i] -> hname;
echo "<br/>";
echo "Image: ";
?>
<html>
<img src=himage alt="himage" style="width:304px;height:228px;">
</html>
<?php
}
?>
,你会期望看到什么,当你倾倒$行?这个“blob”是图像的二进制数据,正如你所描述的那样。如果你想通过'json_encode'传输它,你可能需要'先base64_encode' blob,然后'base64_decode'它被接收后...... –
我没有看到你实际尝试使用blob数据的位置在你的代码中。我甚至不会在你的帖子中看到问题。 –
@cale_b问题是当我试图显示数据的页面是空的 – mattdoesnthaveaclue