I Need My PHP Page to Show My Blob Image from MySQL Database

I need my PHP page to show my BLOB image from mysql database

In your current case, you have two upfront options.

The first, and the one I don't recommend if you have numerous images like this, is to use inline base64 encoding. This is done with:

<img src="data:image/jpeg;base64,<?php echo base64_encode($image); ?>" />

A copy/paste version, using your existing code:

echo '<dt><strong>Technician Image:</strong></dt><dd>'
. '<img src="data:image/jpeg;base64,' . base64_encode($row2['image']) . '" width="290" height="290">'
. '</dd>';

The second method is to create an "image" PHP file that takes the ID of the image in the database as a query-string parameter and outputs the image. So, your HTML would look something like:

<img src="image.php?id=<?php echo $image_id; ?>" />

And your PHP page would look something similar to:

<?php
$id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? intval($_GET['id']) : 0;
$image = getImageFromDatabase($id); // your code to fetch the image

header('Content-Type: image/jpeg');
echo $image;
?>

Display all images stored as BLOB data from MySQL database

First you need to remove the if(isset($_GET['id']) statement because you want to display all images.

Next, query all images by changing your query to query without an id

$query = mysql_query("select * from `blob`");

Next, store the image data to an array.

$images = array();
while ($row = mysql_fetch_assoc($query)) {
$images[] = $row['image'];
}

Finally, display all images. (Got the code to display multiple blobs from here)

/* header should be removed
header("content-type: image/jpeg"); */
foreach ($images as $image) {
echo '<img src="data:image/jpeg;base64,'. base64_encode($image) .'" />';
}

PHP display image BLOB from MySQL

Try it like this.

For inserting into DB

$db = new mysqli("localhost", "root", "", "DbName");
$image = file_get_contents($_FILES['images']['tmp_name']);
$query = "INSERT INTO products (image) VALUES(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $image);
$stmt->execute();

For accessing image from Blob

$db = new mysqli("localhost", "root", "", "DbName");
$sql = "SELECT * FROM products WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param('s', $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';

Displaying BLOB image from Mysql database into dynamic div in html

1) Base64 option

Work with a single line, image/png for a png image and image/jpeg for a jpg one :

echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';

example :