MySQL Forums
Forum List  »  Quality Assurance

Re: inserting images in database
Posted by: Noel Whitemore
Date: July 03, 2012 05:47PM

Hi,

I'll start with the basics:

1. Create a column in your table that uses one of the BLOB types (choose the one that's big enough to accommodate whatever size images you're inserting into the database).

2. You then need to "read in" your image using a script - how you do this depends on what language you're using, but if it's PHP then you can use file_get_contents() - this will save the image to a string. You might also want to use getimagesize() to make sure the file is the expected size.

3. To insert the image into the database you then just need to run a query like this:

INSERT INTO `your_table` (image_blob) VALUES ('$image');

If you need any more help please say so. Please keep in mind that there are some performance drawbacks with storing large files in a database, but (on the plus side) it's a lot easier to manage access to them and easier to retain different versions of the same file without having to use convoluted naming schemes.

Noel

Options: ReplyQuote


Subject
Views
Written By
Posted
2370
June 27, 2012 06:23AM
Re: inserting images in database
10446
July 03, 2012 05:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.