0

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.

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

4 Comments

I tried this. But it's not displaying anything when I tried to run the php file. Can I actually store a BLOB data into json just like that ?
@SOFT1234 For why you are use BLOB for store text? May be best way - use other filed type for this, TEXT for example? Here you can read "how-to convert blob to text".
it's not a text. its an image.
@SOFT1234 in your first post you talk "All I want is to store it as json to be used in Android application." Json is not image, it's text. Here sample with image blob, or others links from google...
0

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. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.