Page 1 of 1
new newbie so go gentle
Posted: Sun Oct 12, 2003 2:13 pm
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
Posted: Sun Oct 12, 2003 2:56 pm
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...
Posted: Sun Oct 12, 2003 2:56 pm
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.
Posted: Sun Oct 12, 2003 3:32 pm
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))
Posted: Sun Oct 12, 2003 3:40 pm
by devork
yah that is the right way for images to be added ....
Posted: Sun Oct 12, 2003 3:54 pm
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