1

I'm creating a 'Social network' site. It's more of a learning exercise than a business venture. I'm not fully clued-up on MYSQL. I want to save 1 image to the database (for each user).

Can I just create another column in my existing table and store the image there (using longblob)? Is there a better way of doing this?

Marc Delisle
  • 8,879
  • 3
  • 29
  • 29
justsimpleshh
  • 97
  • 1
  • 10
  • I think, you should store images on physical disk and store path on database for performance. – Mehmet Ince Nov 05 '13 at 15:48
  • Here's another question: Do you **really** need these in the database, or would you rather simply store a path to the physical image on the disc (and hence not have to go through PHP/server sided script when you want to serve the actual photo). – h2ooooooo Nov 05 '13 at 15:49
  • What I'd do is creating a new table called UserPictures or something, with at least 3 columns. picid,userid,picturemap, the picid stands for the primary key of your table, userid stands for the id of the user who has that profile picture, then picturemap is your longblob magical field thing. Heh. But since you only want 1 image per user, then it MIGHT be a good idea to put just a new column in your user table. – David Merinos Nov 05 '13 at 15:50
  • @h2ooooooo How would i go about doing that? Do you have a useful link that will help me get from the 'upload_file form' to the saving of the image on physical storage? – justsimpleshh Nov 05 '13 at 16:20
  • 1
    @user2953181 Save the file when uploading (there's SEVERAL tutorials for this - just make sure it's an image so people don't upload PHP shells - again - there's SEVERAL tutorials for this) and store the path in the DB. – h2ooooooo Nov 05 '13 at 16:24
  • @h2ooooooo sorry but im in dianeed for your help -its related... http://stackoverflow.com/questions/19908125/saving-file-path-to-database-sql – justsimpleshh Nov 11 '13 at 21:52
  • @UKAWW But you accepted a solution 19 hours ago? – h2ooooooo Nov 12 '13 at 09:25
  • @KayNelson yes thankyou, **WHAT I DID** is just create another column, then added the path to that column, it would probably be neater to create a new table but it wasn't 100% necessary so i didn't. – justsimpleshh Nov 25 '13 at 13:18
  • Great! thats good! Any of the answer that are correct or did you use a different syntax? – Mad Dog Tannen Nov 25 '13 at 13:19
  • 1
    @KayNelson yeah... h2ooooo's comment ^^ was the most helpful ... if not only, then i eventually got it right by experimenting and looking at other sites. – justsimpleshh Nov 25 '13 at 13:24

2 Answers2

0

I think it depends on how the data will be presented at the presentation layer. You could store the location of the image file rather than the image itself in the database table

It's all about using the right storage for the right things.

Mike
  • 2,391
  • 6
  • 33
  • 72
0

You can store images in a table no problem. Allthough many might disagree its the best way to go. (You should better store the path to the physical file)

A query like this might work

INSERT INTO Images (Image) VALUES(LOAD_FILE('C:\Sourcetoyourfile.jpg'));
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55