kasrsf kasrsf - 12 days ago 8
MySQL Question

Can i insert an image in a MYSQL DB table?

is there a way to insert pics(not url,the pic)into a MYSQL table made with phpmyadmin?
and if there is when i want to get that picture and insert it in the page , what should i do? :)

Answer

It is possible (using the BLOB type) but it is almost always better to just store the image in the filesystem and just store the path to the image in the database.

A few reasons why off the top of my head:

  1. BLOBs will balloon the size of your database, making backups and restores potentially more difficult (although some might argue that it makes it easier since you only have to back up the database rather than the database plus a bunch of files).

  2. Storing the data as BLOBs could cause performance issues if you have lazy code that uses select *.

  3. Serving the images from the filesystem will be faster than serving them from the database, and reduce load on the db server.

  4. You get some flexibility with where you serve images - for example if you want to move them to a CDN in the future.