new newbie so go gentle

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
buzzby
Forum Newbie
Posts: 9
Joined: Sun Oct 12, 2003 2:13 pm

new newbie so go gentle

Post by buzzby »

i have just written my first php scripted html page. i feel happy. i now want to incorporate graphics that i want in a database. i do not fully understand how having images in a database rather than in a html page differs. any hints in this area would be grateful. how do i configure mysql and php to be able to bring out the images onto my html site?

i have got mysql on my server to work. any explanations on how to use this facility wouldbe helpful

cheers for your time.

alot of you were once where i am right now. soon i wont be here anymore
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

have you downloaded php manual if not then download it from php.net/doc/
you can find the basic php scripting and all functions detail...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Personally I wouldn't store images in a db - just add them to your html templates (if you are using templates?).

If you need to call an image dynamically, you could echo an image $var in the img tag in the html file:

<img src="<?php echo $image_path; ?>" />

If only some pages have the image and others not, you'd maybe want to echo a var containing the entire img tag (set to null for no image).

Depending on your needs, it could be that it's convenient to store the image names in the db, but perhaps not the actual images.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

I would agree w/McGruff.
Storing images in a db is going to create a lot of overhead since to get the image you'd have to: Connect to the mysql server, select the table, run the query, get the results, and then display the image. Store them on disk just like you would normally in html ( <img src="some/directory/file.jpg" /> ). However, if you are determined to store the images in a db, you will need to store them in the database as "binary data" ( tinyblob, blob, etc ). Another good idea would be to store:
file name
width x height
alt text (if any)
location of original image (on hard drive) ... This is good if you don't do a lot of moving things around

After you get the image into the database read up on connecting to a mysql db and performing a query (http://us3.php.net/manual/en/ref.mysql.php (in particular mysql_connect() and mysql_query))
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

:arrow:
yah that is the right way for images to be added ....
buzzby
Forum Newbie
Posts: 9
Joined: Sun Oct 12, 2003 2:13 pm

Post by buzzby »

dont get me wrong. the only thing i am determined to do is get to know mysql and php at my pace. if it works out that i dont need images in a mysql thingy then fine. i like what was said about including the image via a php 1 liner script. i am just getting into php and know more about php than i did 12 hours ago. cheers for your help people
Post Reply