Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How to insert and display images using php and mysql?

user-image
Question ajoutée par Zack Rose
Date de publication: 2013/09/25
Jargam Abbas Sayyed Mohammad Azam
par Jargam Abbas Sayyed Mohammad Azam , Senior Software Developer , Trimax Infrastructure Ltd.

If you want to insert a image in my sql database. Its taken a time to retrieve a image from database and if you stored a only path of image then it run fast.

 

Create table tmp_img

(

id int - act as primary key

name varchar - used to store image name

path varchar - used to retrieve a images on a page

)

 

And create a one folder in your application and if write a code on copy a image on your application folder.

rizwan yahya
par rizwan yahya , Team Lead , Logo Design Guru

Can you explain it further? you mean creating an image with php and saving it into mysql,  there are numbers of ways to create an image with php GD libraray and imagemagic are the most widely used, i would not recomend to store image in mysql but  if you really want it, create an Longnblob type field and put the image data in that. 

Zeeshan Munshi
par Zeeshan Munshi , Senior Software Developer , MAXVAL TECHNOLOGIES Pvt. Ltd

Working with images is quite easy task in MySQL  using php code. Some years back managing images in relational database is quite complex task as at those times relational databases are able to store only textual data so file path to the images are stored in database and images are stored and retrieved externally. Also special  file functions are necessary for retrieving  images this way and this approach is system dependent (because of path names used). Nowadays, almost all major DBMS support storing of images directly in database by storing images in the form of binary data. Here, I am explaining the method of storing and retrieving images in MySQL database using PHP code.

Inserting images in mysql-:

MySQL has a blob data type which can used to store binary data. A blob is a collection of binary data stored as a single entity in a database managemensystem. Blobs are typically images, audio or other multimedia blob objects. MySQL has four BLOB types:

  • TINYBLOB
  • BLOB
  • MEDIUMBLOB
  • LONGBLOB

All these types differ only in their sizes.

For my demonstration, lets us create a test table named test_image in MySQL having3 columns show below-:

  • Id (INT) -Act as primary key for table.
  • Name (VARCHAR) – Used to store image name.
  • Image (BLOB) – Used to store actual image data.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?