Complicated Mind

March 31, 2005

Retrieving Image File from MySQL using PHP

Filed under: Open Source

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

Comments »

The URI to TrackBack this entry is:
http://belutz.blogsome.com/2005/03/31/retrieving-image-file-from-mysql-using-php/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here