MySQL moron

They have: 10 posts

Joined: Nov 2002

How would one have images in a database?

Where is a good place to learn BASIC MySQL? I have gone to the MySQL site and I will continue to go there for a long time but I am looking for more of a "how to".

ie... where do I start? Where did you all start?

Thanks at ya!

somethines you can and sometimes
you can't.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I don't know of any tutorials for mySQL. I've just learned from reading docs, and (mainly) trial and error.

In response to your question of images kept within a database, you'll want to use a BLOB datatype. The BLOB datatype can store up to 64KB. If your images are larger, you can use a MEDIUMBLOB, which can hold up to 16MB.

Storage is the easy part. The real trick is getting the images from the user (I'm guessing via an HTML form), and into the database. Printing the images from the database isn't as big of a chore.

Lemme see if I can find a tutorial somewheres....

Mark Hensler
If there is no answer on Google, then there is no question.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Wow, it's hard to find tutorials... Alright, I haven't read these, but they seem to be close enough to mention.

Binary Data + MySQL + PHP:
http://www.phpbuilder.com/columns/florian19991014.php3

Simple Form-Based Image Upload:
http://www.phpfreaks.com/tutorials/36/0.php

Most everything I found used PHP as the language of choice. Not very surprising. I did find small snippets of C/C++, and one small snippet of Java. Nothing on ASP (for obvious reasons).

If you have any specific questions, feel free to post in our Server-Side Scripting forum. Smiling

Mark Hensler
If there is no answer on Google, then there is no question.

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

As a general rule, I think that it is a waste to store images in the database. Storing the image name is usually a better option.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I agree. I only know how to do it because I inherited a project where the images were already in a DB.

They have: 10 posts

Joined: Nov 2002

Quote: Originally posted by mairving
As a general rule, I think that it is a waste to store images in the database. Storing the image name is usually a better option.

I think that I can imagine how that is done but that does not mean that I am right.

Could you please give me an idea of what the structure of a database like you mentioned would look like?

MARK: Thanks for the links...

somethines you can and sometimes
you can't.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

For the other option, the images would be saved somewhere in your web path. Then, in your database, simply store the URL to the images. When you want to display a certain image, you query for the image's URL, and print it in tags.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 10 posts

Joined: Nov 2002

My only problem at this point is that I have no idea as to how to create these databases. I have a basic understanding... I can make tables. ie.

database name MY PET CATS
Fields NAME, SEX, AGE, PIC (this is where I would want to put the image)

But as far as having it work on the server... that is another story.

somethines you can and sometimes
you can't.

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.