Home > Archive > PHP Language > January 2006 > Storing images i MySQL using PHP?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Storing images i MySQL using PHP?
|
|
| Jakob Rohde 2006-01-10, 7:01 pm |
| Hi,
I have Googled and searced in various other ways, but I have been unable
to find usable information about how to store and retrieve image files
in a MySQL-database using PHP5.
Can you please guide me to one or more sites or other sources which
contain this information?
TIA,
Jakob
| |
|
|
| Don Freeman 2006-01-11, 6:57 pm |
|
"Jakob Rohde" <jakob.rohde@gmail.com> wrote in message
news:43c42927$0$38669$edfadb0f@dread12.news.tele.dk...
> Hi,
>
> I have Googled and searced in various other ways, but I have been unable
> to find usable information about how to store and retrieve image files in
> a MySQL-database using PHP5.
>
I was going to do this when I read in a couple of sources that it is better
to use the file system to store the image and just keep the location in the
db. Which is what I did, and it works very well but now am wondering if
there are some advantages to using the db to store the image. What was your
deciding point?
Thanks,
Don
--
Ever had one of those days where you just felt like:
http://cosmoslair.com/BadDay.html ?
| |
|
| "Don Freeman" <freemand@sonic.net> wrote in message
news:43c559b4$0$95994$742ec2ed@news.sonic.net...
>
> "Jakob Rohde" <jakob.rohde@gmail.com> wrote in message
> news:43c42927$0$38669$edfadb0f@dread12.news.tele.dk...
> I was going to do this when I read in a couple of sources that it is
> better to use the file system to store the image and just keep the
> location in the db. Which is what I did, and it works very well but now
> am wondering if there are some advantages to using the db to store the
> image. What was your deciding point?
>
> Thanks,
> Don
> --
> Ever had one of those days where you just felt like:
> http://cosmoslair.com/BadDay.html ?
I think you're right there - databases aren't filesystems, at least not
MySQL. Performance comparisons will tell the whole story, though.
dave
| |
| Norman Peelman 2006-01-12, 9:55 pm |
| "Don Freeman" <freemand@sonic.net> wrote in message
news:43c559b4$0$95994$742ec2ed@news.sonic.net...
>
> "Jakob Rohde" <jakob.rohde@gmail.com> wrote in message
> news:43c42927$0$38669$edfadb0f@dread12.news.tele.dk...
in[color=darkred]
> I was going to do this when I read in a couple of sources that it is
better
> to use the file system to store the image and just keep the location in
the
> db. Which is what I did, and it works very well but now am wondering if
> there are some advantages to using the db to store the image. What was
your
> deciding point?
>
> Thanks,
> Don
> --
> Ever had one of those days where you just felt like:
> http://cosmoslair.com/BadDay.html ?
>
>
I store images in MySQL because:
1: I find it very easy to do...
2: No need to worry about the db being out of sync with the filesystem (a
filename in the db that points to a file/image that no longer exists, etc.)
3: Easy backups (they contain everything in one file)... AND the backups
zip up really tight for archival storage.
Norm
--
FREE Avatar hosting at www.easyavatar.com
| |
|
| "Norman Peelman" <npeelman@cfl.rr.com> wrote in message
news:9jDxf.186$Zj7.1@tornado.tampabay.rr.com...
> "Don Freeman" <freemand@sonic.net> wrote in message
> news:43c559b4$0$95994$742ec2ed@news.sonic.net...
> in
> better
> the
> your
>
> I store images in MySQL because:
>
> 1: I find it very easy to do...
> 2: No need to worry about the db being out of sync with the filesystem (a
> filename in the db that points to a file/image that no longer exists,
> etc.)
> 3: Easy backups (they contain everything in one file)... AND the backups
> zip up really tight for archival storage.
>
There is a massive amount of overhead doing that, though. It's impinging
your site's ability to scale... It's far more sensible to keep the images
out of the DB and link to them. Just make sure that whatever updates the
files also triggers an update of your database. Putting the work in on
every access doesn't make as much sense as putting just a bit more work in
when the data changes, and only then...
>
> Norm
>
dave
> --
> FREE Avatar hosting at www.easyavatar.com
>
>
| |
| Jim Michaels 2006-01-19, 3:57 am |
| restores are a pain though (you'll probably never need to do one). you have
to break up the inserts into chunks of 900k or something like that I read in
another post.
if you have a lot of thumbnails to display on a page I hear you get a
performance hit.
I haven't had any problems, but then I haven't had a lot of images to
display.
you can use mysqli functions like mysqli_prepare() etc or use
mysql_real_escape_string() and stripslashes() on your data. mysqli
functions would make the db queries cached I hear(meaning faster). Hilarion
says to avoid dynamic SQL statements like "SELECT image FROM myimages WHERE
id=$myid" because they won't be cached.
Who knows - maybe it would speed things up by half or a quarter.
"Norman Peelman" <npeelman@cfl.rr.com> wrote in message
news:9jDxf.186$Zj7.1@tornado.tampabay.rr.com...
> "Don Freeman" <freemand@sonic.net> wrote in message
> news:43c559b4$0$95994$742ec2ed@news.sonic.net...
> in
> better
> the
> your
>
> I store images in MySQL because:
>
> 1: I find it very easy to do...
> 2: No need to worry about the db being out of sync with the filesystem (a
> filename in the db that points to a file/image that no longer exists,
> etc.)
> 3: Easy backups (they contain everything in one file)... AND the backups
> zip up really tight for archival storage.
>
>
>
> Norm
>
>
> --
> FREE Avatar hosting at www.easyavatar.com
>
>
|
|
|
|
|