BLOB field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Arsench2000
Forum Commoner
Posts: 38
Joined: Sat Sep 15, 2007 8:18 pm

BLOB field

Post by Arsench2000 »

Hello world,

Can you please help me.I have a blob field and want to insert and read image, but don't know how to do that.I want to insert data with images into mysql db and then read that in php.


Thank a lot
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Do a Google search for "Storing images in MySQL".

I'd recommend not storing the images in MySQL, but rather store the images in the file system & store the path to the images in the database. There is a lot of overhead when storing images in the database - which leads to slow page loads.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
emmbec
Forum Contributor
Posts: 112
Joined: Thu Sep 21, 2006 12:19 pm
Location: Queretaro, Mexico

Re: BLOB field

Post by emmbec »

What if instead of images he was storing just regular files, lets say ZIP, or DOC files. Is it still a lot of overhead?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: BLOB field

Post by Luke »

Why wouldn't you just store the file in the filesystem... that is, after all, what it's for.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: BLOB field

Post by pickle »

emmbec wrote:What if instead of images he was storing just regular files, lets say ZIP, or DOC files. Is it still a lot of overhead?
Ya, there is still overhead. If a request comes in for a file, Apache has to first look at the file and decide what to do with it. If it's just a regular image/zip/doc/whatever file, Apache just opens the file & sends it along.

If it's a file like what the original poster wanted to do, Apache would have to invoke the PHP engine, which would then query the database, which would return the value, which would then stream the file back to the user. Not only is there query and PHP engine overhead, there's also memory overhead because the file has to be stored 3 times (once in the file that is the MySQL database, once in the MySQL result set, and once in the PHP file), rather than just once in the filesystem.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply