PHP & MySQL

naoshad's picture

He has: 23 posts

Joined: Feb 2005

Hi all,
is there any way to save image in MySQL database using PHP Confused

Busy's picture

He has: 6,151 posts

Joined: May 2001

You dont want to save the actual image in the database, just save the images name (and details like width, height etc if you want).

naoshad's picture

He has: 23 posts

Joined: Feb 2005

Thanks Busy. For your information Smiling

They have: 3 posts

Joined: Mar 2005

What you want to do is take a look into BLOB. Binary Large Object that can hold a variable amount of data.

MySQL: BLOB:
http://dev.mysql.com/doc/mysql/en/blob.html

But it is not recommended for smaller projects like yours because the comparison work done to the actual process and ram load is greater than just storing it regularly. Not until you have very large files does it become somewhat useful.

naoshad's picture

He has: 23 posts

Joined: Feb 2005

Thnaks Smiling

They have: 8 posts

Joined: Feb 2005

Two ways of dealing with that are to store the files on the filesystem, and then only store the files paths in the db, or to store the binary data of the image in a blob field.

If the pictures are big, you might also want to go one step further and store a single file across multiple db records. I've never done it myself, but I've heard that people sometimes have problems (in MySQL) loading or storing more than 1MB into a single field, so they cut the file up and store it in slices.

The second option is obviously more complex, so I'd go for the first if possible.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.