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.

1
  • Don't use "SELECT *". Name the columns you actually want returned. (We've got no chance otherwise) Commented May 11, 2014 at 18:53

1 Answer 1

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

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.