我试图将图像存储到数组中。我的php代码如下:
$query_search1 = "SELECT profilePicture FROM rocket WHERE username='".$rocketName."'";
$query_exec1 = mysqli_query($db->getConnection(),$query_search1) or die(mysqli_error($db->getConnection()));
$row1 = mysqli_fetch_assoc($query_exec1);
//$rocketPic = $row1['profilePicture'];
$json = array();
//$json['rocket_profile'][] = $row1;
if(mysqli_num_rows($query_exec1)){
while($row2 = $row1){
$json['rocket_profile'][] = $row2;
}
}
profilePicture的数据类型是BLOB。以下是我得到的错误:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)
我想要的只是将其存储为json,以便在Android应用程序中使用。
答案 0 :(得分:2)
你有一个无限的while循环。这会占用你所有的RAM内存。检查循环逻辑。
答案 1 :(得分:1)
你有一个无限循环,试试这个:
$query_search1 = "SELECT profilePicture FROM rocket WHERE username='".$rocketName."'";
$query_exec1 = mysqli_query($db->getConnection(),$query_search1) or die(mysqli_error($db->getConnection()));
$json = array();
if(mysqli_num_rows($query_exec1)){
while($row1 = mysqli_fetch_assoc($query_exec1)){
$json['rocket_profile'][] = $row1;
}
}
答案 2 :(得分:0)
您可以在ini_set('memory_limit', '-1');
变量之前设置$query_search1
来解决错误:Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)
但我建议您检查一下逻辑,而不是更改资源内存限制。 :)