将 MySQL 用于图库的最佳方式?
可能的重复:
最好的方法是什么在MySQL中存储一系列图像?
这是我几个月前为朋友建立的第一个网站: http://www.jpsinghphotography.co.uk
我想将其重建为我的第一个 PHP/MySQL项目,但我有几个关于如何构建数据库的问题。
1)是否最好使用BLOB数据类型将实际图像文件放入数据库中;或存储文件名并使用它们从服务器上的另一个文件夹查找图像?
2)我是 SQL 新手,我最初设想为我想要创建的每个图库都有一个单独的表。按类别排序的表格在哪些方面更好?
感谢您的任何和所有建议
Possible Duplicate:
What is the best way to store a series of images in MySQL?
This is the first website that I built for a friend a few months ago:
http://www.jpsinghphotography.co.uk
I want to rebuild it as my first PHP/MySQL project, but I had a couple of questions regarding how to structure the database.
1) Is it best to put the actual image files in the database using BLOB data types; or store the file names and use these to look up the images from another folder on the server?
2) I'm new to SQL and I'd initially imagined a seperate table for each gallery I want to create. In what ways is one table sorted by category better?
Thanks for any and all advice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎来到 stackoverflow。
您可以将图像数据放入MySQL中,但通常最好将它们作为文件放入。这使得它们更容易缓存和缩略图,否则您必须自己做。
按类别排序的一张表格可以让您在类别名称方面更加灵活,并且可以更轻松地在类别之间移动图像,以及从多个类别获取信息,例如每个类别的图像数量。
按
Welcome to stackoverflow.
You can put image data in MySQL, but it's usually better to put them as files. That make them easier to cache and thumbnail, otherwise you have to do them yourself.
One table sorted by category would allow you more flexibility in category names and make it easier to move images between categories as well as get information from multiple categories such as image count of each category.
我会坚持提供参考,即。 MySQL 表中的文件名。将图像作为 BLOB 放入表中意味着您现在维护照片的两个副本。如果您的主要应用程序是存储历史记录,那么这是有道理的,但除此之外,对原始应用程序的简单引用可能会更好。
第二个问题可能是存储空间:如果您对图片进行 BLOB,您显然会处理一些非常大的表。这可能是问题,也可能不是问题。
正如其他人所发布的,为每个画廊创建多个表是明确的禁忌,并且违背了使用关系数据库的整个理念。只需向图片表中添加一列来保存图库 ID,并使其成为唯一键的一部分。您可能还需要一个单独的画廊表,以使其更加“规范化”。
I would stick to providing a reference ie. the file name in the MySQL table. Putting the images in the table as BLOBs would mean you're now maintaining two copies of your pics. If you're primary application is to store history, this makes sense, but otherwise, a simple reference to the original is probably better.
A secondary issue may be storage space: you'd obviously be dealing with some very large tables if you BLOB the pictures. That may or may not be a problem.
As others posted, creating multiple tables for each gallery is a definite no-no and against the whole philosophy of using a relational database. Simple add a column to the pictures table that holds the gallery id and make it part of the unique key. You may also want a separate gallery table too, to be more 'normalized' about it.