I wanted to know how I could retrieve an image from the database, used php7, the image is stored in the database in type BLOB, I searched the internet and they were very old examples and none worked here, could anyone help me?
I wanted to know how I could retrieve an image from the database, used php7, the image is stored in the database in type BLOB, I searched the internet and they were very old examples and none worked here, could anyone help me?
To insert the image do the following:
$db = mysqli_connect("localhost","root","","DbName"); //keep your db name
$image = addslashes(file_get_contents($_FILES['images']['tmp_name']));
$query = "INSERT INTO products (id,image) VALUES('','$image')";
$qry = mysqli_query($db, $query);
To access the Blob image
$db = mysqli_connect("localhost","root","","DbName"); //keep your db name
$sql = "SELECT * FROM products WHERE id = $id";
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>';
I hope it works for you!