What is the best datatype to use to store images of jpeg or gif format in a mysql database . (I'd be storing about 20 to 50 such images).
thanks
What is the best datatype to use to store images of jpeg or gif format in a mysql database . (I'd be storing about 20 to 50 such images).
thanks
My recommendation would be to store the files in the server's filesystem, and just use the database to store info about them, including the filename and possibly the directory name if needed. But if you really feel a need to store the actual images in your DB, then you'll want to use a "blob" type.
poncho4u:
Its generally not a good idea to store images in a database. Besides, its not the bits of the image you are searching on, but rather the meta description of the image that should be stored like:
filename
location
width
height
description of image
So for example lets say you have 50 images consisting of flags of the world. What point would it be to store the pictures themselves in a database when all you really want is, to say, search on the country name?
Storing an image in a database won't buy you anything. Storing the meta information of the images will.
If you're storing such a small number, it is probably not worth storing them in the database. The management advantages of doing so aren't going to outweigh the significant difficulty of setting up code to do so.
Supposing you did want to, the best way is to use a BLOB (or perhaps LONGBLO datatype, then use a prepared query with a binary parameter containing the image binary data to insert / update.
Then use a normal query to select the image, retrieving it as binary data.
Mark
As stated by others it is much better to store the images in your files system and it can be organized anyway you wish like a folder for sports, possibly with subfolders of baseball, or football or boxing heck anything. Then just store the links to the files in your database then no matter how your file structure is setup then the proper link will still work.
Yes either a BLOB (binary large object) or possibly LARGEBLOB data type would be required to store such data in a database, but why go through all that trouble?