Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Storing an image in mySQL

Hi Guys,

The title says it all. What is the best way of storing an image or image url into a mysql database?

I'm looking to display the image within an iphone app which I am working on.

Thanks!

2 Answers

James Barnett
James Barnett
39,199 Points

There's a datatype in SQL called a blob that's what you want to use.

Thanks for the reply James.

I wasnt too sure how to use it as I'm still learning about mySQL.

Someone told me that I could store the image URL as a varchar too, is this correct and is there much of a difference between the two types?

image_url varchar(2083) COLLATE utf8_unicode_ci NOT NULL

Many Thanks, Andrew

James Barnett
James Barnett
39,199 Points

Andrew B - There's a big difference between the 2. In one case you are storing the image somewhere like on a CDN maybe and you have a link in stored in a database. On the other hand you are storing the actual image in the database itself.