Thursday, March 31, 2005

Retrieving Image File from MySQL using PHP

Many people ask me about this. Database example: database name = "test" table name = "image" table column 1 = id, data type = int, special attributes = auto_increment, primary key table column 2 = image, data type = blob this is the sql script:

use test; create table image (id int(11) NOT NULL auto_increment, image blob, PRIMARY KEY(id));
this is the php script:
<?      header("Content-type: image/jpeg"); // act as a jpeg file      mysql_connect("your_host","your_db_username","your_db_password");      mysql_select_db("test"); // use the 'test' database      $query = "select image from image where id = $id";      $result = mysql_db_query("test",$query);      $row = mysql_fetch_array($result);      $img = $row['image'];      echo ("$img"); ?>
There you go, you will see the image that you store in MySQL database using blob data type. Enjoy! :D

posted by Belutz @ 3/31/2005 11:31:00 PM


Links to this post:

Create a Link

» Home

my mood: The current mood of belutz at www.imood.com

Name :
Web URL :
Message :

Who Links Here

BlogFam Community

Free Shoutbox Technology Pioneer

Powered by Blogger
Subscribe with Bloglines
Get Firefox!
XFN Friendly

Ubuntu Linux

Gelang Merah Untuk Anak Indonesia

Listed on BlogShares

Creative Commons License

Design by Beccary