SOFT1234
SOFT1234

Reputation: 181

Unable to store image from MySQL into PHP array

I'm trying to store the image into an array. My php code as below:

$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;
    }
}

Data type for profilePicture is BLOB. Below is the error I got:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)

All I want is to store it as json to be used in Android application.

Upvotes: 0

Views: 79

Answers (3)

Artem
Artem

Reputation: 691

You have an infinity loop, try this:

$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;
    }
}

Upvotes: 1

Eko Junaidi Salam
Eko Junaidi Salam

Reputation: 1681

You can set ini_set('memory_limit', '-1'); before your $query_search1 variable to solve the error :Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)

But I suggest you to check your logic instead of change the Resources memory Limit. :)

Upvotes: 0

Edgar Orozco
Edgar Orozco

Reputation: 2782

You have an infinite while loop. This consume all your RAM mem. Review your loop logic.

Upvotes: 2

Related Questions