标签云

微信群

扫码加入我们

WeChat QR Code


storing-images-in-db-yea-or-nay

2018年12月11日08分18秒

Nevir: What information are you specifically after? What do you feel is lacking from phpguy's and Mat's answers?

2018年12月10日08分18秒

Sorry, I did not mean to bounty this (ran into a UI bug with SO), but cannot remove the bounty

2018年12月11日08分18秒

This code looks like PHP3 (or maybe 4), which register_globals enabled. You don't want to run this code, and it will also not work on a semi up to date PHP installation (which is version 5).

2018年12月11日08分18秒

-1 for addslashes() where mysql_real_escape_string() is needed. Can we please stop giving people code with SQL injection vulnerabilities in it? (No, addslashes() is NOT good enough.)

2018年12月11日08分18秒

I didn't downvote, but it might be due him implying that you should NEVER do it, as opposed to saying it's a bad idea most of the time. I agree with him generally, but not in 100% of cases. There can be considerations other than performance. For example I'm working on something now where performance doesn't matter at all. Other factors such as centralisation, simplicity and backups mean that in this case storing in the database makes sense. Another common reason is replication.

2018年12月10日08分18秒

On the other hand storing data in db is OS independent, which can be nice for weird filenames. db can store multiple files with same filename, the OS cannot. It has no read/write/delete issues. It doesn't need an additional backup system. And, it's not public. So sometimes it's fast in development. Btw. nobody is forcing you to store everything in the same database, in the end it all ends up on a disk.

2018年12月11日08分18秒

AlexWeinstein, You are confusing binary data with fixed width data. Binary data can be fixed width as well. And fixed width data is not good for all situations. Indeed, in many situations you would benefit from variable width data: read last paragraph of dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html

2018年12月11日08分18秒

Agree with Pacerier on this, BINARY(16) is stored fixed. As for BLOB: A BLOB has a fixed width pointer to data stored outside the table. That is unlike varchar or varbinary which store it inline.Searching a blob requires some extra steps, but leave it out of your WHERE clause and it is fine.

2018年12月11日08分18秒

i also think storing files in the filesystem is very broken and non-portable. what if the file gets deleted?

2018年12月10日08分18秒