Blobs, files, and file paths
When it comes to storing images and files in databases, there are two ways you can achieve this:
- MySQL offers four
blob
data types of varying sizes that will store files and images in the database.
This method is okay if you have small files and not too many records. Too many or large images can impact database performance, and developers often tend to avoid this method. Just because you can store an image in the database doesn't mean that you should.
- You can set up a
VARCHAR(255)
field, in which you can store a file path and name pointing to a file or image stored somewhere on your network.
This is the preferred method, especially for many or large files, and requires no messing around with the server settings. The application can read the path and name from the database and then load the file and do what it needs to with it – display it, transfer it, or whatever. However, it does require that the file storage...