Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing pictures in a MySQL database?

Status
Not open for further replies.

JProg

Programmer
Apr 4, 2002
88
JP
Hi Everyone,

I am wondering if it is possible to store pictures in a MySQL database? If so how does one go about this (particularly what SQL datatype would a picture be stored as?). Assuming that it is possible to store pictures in a MySQL database, are there any disadvantages to doing so? For example would storing a picture in MySQL take up lots more storage space than simply keeping pictures in directories?

Thanks for your help.

Regards

David
 
You can certainly store pictures in a MySQL table. You would use a Blob field for storage. The Blob type you use depends on the maximum expected size of your picture data. TINYBLOB allows up to 255 bytes (not very useful for a picture); BLOB allows up to 64kB; MEDIUMBLOB allows up to 16.7MB; and LONGBLOB allows up to 4.2GB. You would normally load the data by means of the LOAD_FILE function, for example:[tt]
INSERT photos (datetaken,description,image)
VALUES
(
'2003-12-25',
'Me opening my present from Mary',
LOAD_FILE('c:/pics/000124.jpg')
)[/tt]

where the file path is located on the MySQL server.

The amount of storage used would be the same as storing the pictures as separate files, give or take a few bytes.

-----
ALTER world DROP injustice, ADD peace;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top