Log in

View Full Version : how I do this



alexdog1805
02-06-2009, 11:38 PM
I want to make a connection between a photo a web site and a database. How can I put a image on an database(mysql)?What is the code that make all this connection!!!! pls help!!!

boogyman
02-06-2009, 11:46 PM
dont store the actual image in the database, but rather save a reference to the image via a url, then query out the url and use that in the image.

Schmoopy
02-06-2009, 11:56 PM
To connect to a MySQL database you need something to connect to it, in this case I'll use PHP but you can do it in other ways:



<?php

$host = "host"; // Host server name here
$user = "user"; // The username your host gives you to connect to the database
$pass = "pass" // The password your host gives you


$con = mysql_connect($host, $user, $pass)

if(!$con)
{
die("Failed to connect to the server" . mysql_error());
}

// Code for selecting the database follows

?>


You need to know the name of your database to connect to it, and what tables you're going to access.

But as boogyman says, just save the url as a string like so:



<?php

$image = "images/flyers/advert.jpg";

$result = mysql_query("SELECT * FROM table WHERE image = $image");
while($row = mysql_fetch_array($result))
{
echo $row['image'];

}

?>