Welcome to Dream.In.Code
Become an Expert!

Join 150,007 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,386 people online right now. Registration is fast and FREE... Join Now!




Storing images in MySql

 
Reply to this topicStart new topic

Storing images in MySql

matt-the-mash
25 Nov, 2006 - 01:26 AM
Post #1

D.I.C Head
**

Joined: 10 Jul, 2006
Posts: 120



Thanked: 1 times
My Contributions
How do i store images in a mysql database?

Does the image file get stored, or just a link to the image location on the server?
User is offlineProfile CardPM
+Quote Post

thef0rce
RE: Storing Images In MySql
25 Nov, 2006 - 04:10 AM
Post #2

New D.I.C Head
*

Joined: 2 Nov, 2006
Posts: 39


My Contributions
storing images is possible but you have to think about performance. The best idea is to store the actual images in a folder and the paths to the images in the database.
User is offlineProfile CardPM
+Quote Post

matt-the-mash
RE: Storing Images In MySql
25 Nov, 2006 - 07:58 AM
Post #3

D.I.C Head
**

Joined: 10 Jul, 2006
Posts: 120



Thanked: 1 times
My Contributions
That makes sense.

How would i call the path from the database?

Say, i wanted to display a picture, thumb nail size in a table with some discriptive text, how do i call the path in the database? (im using php)

This post has been edited by matt-the-mash: 25 Nov, 2006 - 08:02 AM
User is offlineProfile CardPM
+Quote Post

k0b13r
RE: Storing Images In MySql
27 Nov, 2006 - 12:49 AM
Post #4

D.I.C Head
Group Icon

Joined: 18 Jul, 2006
Posts: 198



Thanked: 1 times
Dream Kudos: 250
My Contributions
You should use
CODE

$data = mysql_fetch_row(mysql_query(SELECT <your field in table> FROM <your table> WHERE <your id or something>));

To show it use
CODE

echo $data[0];

User is offlineProfile CardPM
+Quote Post

matt-the-mash
RE: Storing Images In MySql
27 Nov, 2006 - 03:52 AM
Post #5

D.I.C Head
**

Joined: 10 Jul, 2006
Posts: 120



Thanked: 1 times
My Contributions
Thanks for the info.

I can now call the image from the database and display it correctly on the screen, but i cant seem to display it in a table.
Every time i put <table> tags around it, i just get a binary output.

Any ideas?
User is offlineProfile CardPM
+Quote Post

snoj
RE: Storing Images In MySql
27 Nov, 2006 - 04:45 PM
Post #6

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
You get binary output because that's how it's stored in the database. IIRC BLOB stands for Binary Large Object. It's basically a file stored in a database instead of in a file system. (In fact you could draw similarities between a database and a file system.)

Anywho, you need to output it without any HTMl, in other words, you'll need to treat the image store in the database just like you would a real image file.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month