在MySQL中存储一系列图像的最佳方法是什么?

在MySQL中存储一系列图像的最佳方法是什么?

问题描述:

我一直在为我的网站制作一个SQL模型,而且我对如何将这些图像存储在我的数据库中以便在网站上使用感到非常矛盾。

I've been working on a SQL model for my website, and I'm really conflicted on how to store these images in my database for use around the site.

首先,每个配置文件将包含相关的10个图像。 4个屏幕截图,包含缩略图和两个额外图像。这些图像将在网站周围使用。

First, each profile will contain a relevant 10 images total. 4 screenshots, with thumbnails, and two extra images. These images will be used all around the site.

是否将每个图像的图像路径存储在自己的列中?一个伙伴告诉我,我应该将所有图像放在它自己的表中并交叉引用它们以获得更好的性能。我会用图像本身同时从配置文件中调用各种信息。

Is storing the image path for each image in it's own column fine? A buddy tells me that I should place all images in it's own table and cross-reference them for better performance. I'll be calling all sorts of information from the profiles around the same time with the images themselves though.

我只是想知道这种事情的常见做法是什么。

I'm just wondering what the common practice for something such as this is.

同样,我没有将实际图像存储在数据库中 - 只是图像路径。

Again, I'm not storing the actual image in the database - just the image path.

将图像存储在文件系统上并将路径存储在数据库中..

Store images on your file system and store paths in database..

如果个人资料包含多个图片,则为图片创建一个单独的表格。

If profile has more than 1 images then create a separate table for images.

个人资料表:

id | name | etc | etc
---------------------
1  | abc  | etc | etc
2  | xyz  | etc | etc

图表:

id | profile_id |     image_url     | image_type
-------------------------------------------------
 1 |     1      | images/image1.jpg | screenshot
 2 |     1      | images/image2.jpg | other
 3 |     2      | images/image3.jpg | screenshot 

现在,您可以创建不同的函数来获取特定配置文件的图像。例如:

Now you can create different functions to get images for specific profile. For example:

getProfileImages( profile_id, image_type=NULL ) {
  // run query by joining profiles and images tables.
  // return images paths
}