2015-04-18 38 views
0

我试图将图像存储到数组中。我的php代码如下:无法将图像从MySQL存储到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应用程序。

回答

2

你有一个无限的while循环。这会消耗你所有的RAM内存。检查你的循环逻辑。

0

您可以设置ini_set('memory_limit', '-1');$query_search1变量之前解决错误:Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)

但我建议你检查你的逻辑,而不是变化的资源内存限制。 :)

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; 
    } 
} 
+0

我尝试这样做。但是当我试图运行php文件时,它没有显示任何内容。我真的可以像这样将一个BLOB数据存储到json中吗? – SOFT1234

+0

@ SOFT1234为什么你使用BLOB存储文本?可能是最好的方式 - 使用其他类型的文件,例如TEXT? [Here](http://myvedham.blogspot.ru/2013/10/read-blob-from-mysql.html)你可以阅读“如何将blob转换为文本”。 – Artem

+0

这不是一个文本。它的一个形象。 – SOFT1234

相关问题