1

I have to show some data in my android application from a external database including an image. I have successfully got text data from the database. Here is my php code. Now I need to get blob data. How can I achieve this..?

$id=$_POST['ID'];

$db_server = mysql_connect($hostname,$username,$password);

if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($database,$db_server);

    $result=mysql_query("select * from names where ID=$id");

    while($row=mysql_fetch_assoc($result)){

        $output[]=$row;
    }

    print(json_encode($output));

    mysql_close($db_server);

?>

Maggie
  • 1,546
  • 16
  • 27
Shashika
  • 1,606
  • 6
  • 28
  • 47

1 Answers1

-3

Its not recommend to pass blob data in json, use url of that image for passing in response.

Swetank
  • 1,577
  • 11
  • 14
  • Images are inside the database. I think there is no unique url for each image. – Shashika Sep 29 '13 at 05:17
  • That's what i am saying don't keep image in database for better performance. But if you want to do same way you have to send as bytes. – Swetank Sep 29 '13 at 05:42
  • Do u have an idea how can I send the image as bytes? – Shashika Sep 29 '13 at 05:51
  • Refer https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data and http://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64 – Swetank Sep 29 '13 at 06:59