how to show an image in php from mysql database example?

Today, We want to share with you how to display an image in php from mysql database example.In this post we will show you how to retrieve image from database in php mysqli?, hear for how to display images from database in Php using MySQL we will give you demo and example for implement.In this post, we will learn about How To Fetch Image From Database In Php ? with an example.

How to show image from database in PHP using MySQL?

show.php page.

<!DOCTYPE html>
	<html>
	<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, intial-scale=1.0"/>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<title>Show Image in PHP - www.pakainfo.com</title>
	<style>
		body{background-color: #f2f2f2; color: #333;}
		.main{box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; margin-top: 10px;}
		h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba(57,73,76,0.35);}
		.img-box{margin-top: 20px;}
		.img-block{float: left; margin-right: 5px; text-align: center;}
		p{margin-top: 0;}
		img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; border:6px solid #f7f7f7;}
	</style>
	</head>

	<body>
		<!-------------------Main Data Content------------------------------>
		<div class="container main">
			<h3>Showing Images from database - demo</h3>
			<div class="img-box">

			</div>
		</div>
	</body>
	</html>
	

db_config.php

<?php

	$host ="localhost";
	$uname = "root";
	$pwd = '89895665898';
	$db_name = "pakainfo";
?>

show.php

<?php
	
	/*-- we included db_config files--*/
	include "db_config.php";

	$result = mysqli_connect($host,$uname,$pwd) or die("Could not connect to database." .mysqli_error());
	mysqli_select_db($result,$db_name) or die("Could not select the databse." .mysqli_error());
	$image_query = mysqli_query($result,"select picturename,img_path from profiles");
	while($rows = mysqli_fetch_array($image_query))
	{
		$picturename = $rows['picturename'];
		$img_src = $rows['img_path'];
	?>
	
	<div class="img-block">
	<img src="<?php echo $img_src; ?>" alt="" title="<?php echo $picturename; ?>" class="img-responsive" />
	<p><strong><?php echo $picturename; ?></strong></p>
	</div>
	
	<?php
	}
?>


I hope you get an idea about store and retrieve image from database in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.