1

Here is a code how I push image into database:

$title = $_REQUEST['title'];
$description = $_REQUEST['description'];
$image = $_REQUEST['image'];
$bdata = addslashes($image);

$query = "insert into Images (title, description, image) values ($title, $description, '$bdata')" or die("Error in the consult.." . mysqli_error($connection));

$result = $connection->query($query);
$connection->close();

I double checked in database and it stores successfully.

Here is a code which gets data from the table:

$query = "select * from Images" or die("Error in the consult.." . mysqli_error($connection));
$result = $connection->query($query);
$events = array();

while ($event = $result->fetch_array(MYSQLI_ASSOC)) {       

    $events[] = $event;
}

header('Content-type: application/json');

echo json_encode($events);

$result->free();
$connection->close();

As result I receive next json:

{
id: "34",
title: "some image",
description: "some description",
image: null
}

As you can see "image" field is null. In phpAdmin I see that there is a data.

Markus Malkusch
  • 7,738
  • 2
  • 38
  • 67
Serge
  • 2,031
  • 3
  • 33
  • 56

1 Answers1

1

First: Use prepared statements to get rid of that annoying SQL injection.


JSON has no native support for binary data:

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.

Use something like Base64, BSON, Smile or UBJSON. See also: Binary Data in JSON String. Something better than Base64

Community
  • 1
  • 1
Markus Malkusch
  • 7,738
  • 2
  • 38
  • 67