In this big and best tutorials, you going to learn how to fetch image from MySQL database in php including other related steps of fetching of image.
Related steps are as follow as:
- The first step is to fetch image and display in table
- The second step is to fetch image and display in div
- The third step is to fetch multiple image and display in table
- Forth step is to fetch uploaded image
- Fifth step id how to fetch image and display
Above step you learn in more information.
Lets start with the step of talked about regarding : How to fetch image from MySQL database in php
Before start with the talked about regarding fetching of image.
First step to create table name called image in the MySQL database.
Below is the SQL query execute or run in phpmyadmin so table is created.
-- -- Table structure for table `image` -- CREATE TABLE `image` ( `id` int(11) NOT NULL, `title` varchar(500) NOT NULL, `imagename` text NOT NULL, `type` varchar(500) NOT NULL, `time` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
After executing the above Sql query table is created as shown below.
Also Read: how to fetch images from database in php?
Now create the configuration file to configure MySQL database connection file name database_connect.php
database_connect.php
After the creation of a configuration file for MySQL database connection
The next step is to insert the image into the MySQL database.
To achieve the inserting of image into MySQL database I have to upload image.
To upload image, create form consisting with input field.
Below is the php script from which you come to know how the image file is uploaded.
How to fetch image from MySQL database in php
Output of above source code is as follow as:
As you can see the declaration of form with action calling file uploading.php.
In that file there php script for uploading of image into the MySQL database.
Also Read: Ajax Image Upload without Refreshing Page using Jquery
Below is the script of uploading image file which is called on click of upload button in the form.
After clicking on upload button, image get inserted into MySQL database and image file is uploaded in folder path of image as it is give in above php script.
To understand more thoroughly below is folder structure.
After uploading two images, the two image get inserted into MySQL database.
And Image file is uploaded in image folder.
Now fetching the image from MySQL database.
To fetch the image from the MySQL database table I have to execute select SQL query depending upon the number of image requirement.
As in the above code you can see that after inserting of images into MySQL database successfully it redirect to display image file for display of image.
The file for display of images is called as the file name users_list.php
users_list.php
How to fetch image from MySQL database in php
Previously Uploaded | Add Image | ||||
Title | Image | Type | Action | |
---|---|---|---|---|