0

I'm attempting to retrieve all the data from a table in MySQL and add it to an array.

Click for Table columns structure

I want to convert the blob into an encoded string and add it to an array with the other two columns and then return it as a JSON string. See below for my attempted code:

<?php 
//Importing Database Script 
require_once('dbConnect.php');

//Creating sql query
$sql = "SELECT * FROM picture";

//getting result 
$r = mysqli_query($con,$sql);

//creating a blank array 
$result = array();

//looping through all the records fetched
while($row = mysqli_fetch_array($r)){

    //Pushing name and id in the blank array created 
    array_push($result,array(
        "pictureID"=>$row['pictureID'],
        "listingID"=>$row['listingID'],
        "listingImage"=>$row [base64_encode('listingImage')]
    ));
}

//Displaying the array in json format 
echo json_encode(array('result'=>$result));

mysqli_close($con);

The code is currently returning with a null value for the blob image.

2
  • 1
    try "listingImage"=>base64_encode($row['listingImage']) Commented Apr 12, 2016 at 20:27
  • of course all this mess could have been avoided if you had saved files on the filesystem as they are supposed to be. Commented May 6, 2016 at 3:52

1 Answer 1

1

Try to change the line :

"listingImage"=>$row [base64_encode('listingImage')]

to

"listingImage"=> base64_encode($row["listingImage"]);
Sign up to request clarification or add additional context in comments.

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.